我正在完成本教程 - > http://ruby.railstutorial.org/chapters/filling-in-the-layout
您可以在此处遇到问题 - > intense-dusk-3202.herokuapp.com/
当我点击标题中的“主页”链接时,它会尝试转到http://intense-dusk-3202.herokuapp.com/root_path
,而不仅仅是http://intense-dusk-3202.herokuapp.com/
这是我的routes.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>
在你帮助我之前,你还需要看其他什么吗?
答案 0 :(得分: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方法。只需直接打电话给他们,不要在他们周围加上引号。