1

我想知道在 rails 中为不同页面设置导航链接的好方法是什么?现在我有什么休息。这是代码

_nav.html.erb

<ul class="nav nav-pills pull-right">
    <%if current_page?(:action => 'new') %>
    <li><%= link_to "Home", root_path%></li>
    <%elsif current_page?(:controller => 'home', :action => 'index') %>
    <li><%= link_to "Contact", home_contact_path%></li>
    <%end%>
</ul>

所以当我做一个<%= render :partial => 'layouts/nav' %>under/views/home/index.html.erb它给我一个错误

No route matches {:action=>"new", :controller=>"home"}
4

1 回答 1

2

您的家庭控制器中没有新操作...查看您的路线,唯一可用的操作是联系...

尝试使用助手 ( current_page?(helper)) 而不是action+ controller。检查rake routes以查看帮助程序。

_nav.html.erb

<ul class="nav nav-pills pull-right">
  <%if current_page?(new_user_registration) %> #check the path helper by `rake routes`
    <li><%= link_to "Home", root_path%></li>
  <%elsif current_page?(root_path) %>
    <li><%= link_to "Contact", home_contact_path%></li>
  <%end%>
</ul>
于 2013-03-02T09:57:50.410 回答