1

我正在完成本教程-> http://ruby.railstutorial.org/chapters/filling-in-the-layout

你可以在这里遇到问题-> strong-dusk-3202.herokuapp.com/

当我单击标题中的“主页”链接时,它会尝试带我去,http://intense-dusk-3202.herokuapp.com/root_path而不仅仅是http://intense-dusk-3202.herokuapp.com/

这是我的路线.rb

SampleApp::Application.routes.draw do
  get "users/new"

  root :to => 'static_pages#home'

match '/signup', to: 'users#new'

  match '/help', to: 'static_pages#help'

  match '/about', to: 'static_pages#about'

  match '/contact', to: 'static_pages#contact'

end

这是我的 app/views/layouts/_header.html.erb 文件:

<header class="navbar navbar-fixed-top navbar-inverse">
  <div class="navbar-inner">
    <div class="container">
      <%= link_to "sample app", 'root_path', id: "logo" %>
      <nav>
        <ul class="nav pull-right">
          <li><%= link_to "Home",    'root_path' %></li>
          <li><%= link_to "Help",    'help_path' %></li>
          <li><%= link_to "Sign in", '#' %></li>
        </ul>
      </nav>
    </div>
  </div>
</header>

在你帮助我之前,你还需要看什么吗?

4

1 回答 1

4

你不应该引用这些助手:

<header class="navbar navbar-fixed-top navbar-inverse">
  <div class="navbar-inner">
    <div class="container">
      <%= link_to "sample app", root_path, id: "logo" %>
      <nav>
        <ul class="nav pull-right">
          <li><%= link_to "Home",    root_path %></li>
          <li><%= link_to "Help",    help_path %></li>
          <li><%= link_to "Sign in", '#' %></li>
        </ul>
      </nav>
    </div>
  </div>
</header>

root_path, help_path, 和所有其他命名的路由助手实际上是 ruby​​ 方法。直接打电话给他们,不要在他们周围加上引号。

于 2012-11-25T15:18:55.057 回答