current_page无法识别家庭'页面路由

时间:2016-04-29 23:11:27

标签: ruby-on-rails routes

我目前正在为我的申请制作一个具有以下路线的应用程序。

refix Verb   URI Pattern                  Controller#Action
        root GET    /                            pages#home
        home GET    /home(.:format)              pages#home
    problems GET    /problems(.:format)          problems#index
             POST   /problems(.:format)          problems#create
 new_problem GET    /problems/new(.:format)      problems#new
edit_problem GET    /problems/:id/edit(.:format) problems#edit
     problem GET    /problems/:id(.:format)      problems#show
             PATCH  /problems/:id(.:format)      problems#update
             PUT    /problems/:id(.:format)      problems#update
             DELETE /problems/:id(.:format)      problems#destroy

_navigation部分文件,如下所示

      <% if !current_page?(home_path) and   !current_page?(root_path) %>
        <bold>Home</bold>  | &nbsp;
      <% else %>
          <%= link_to "Home", home_path %> | &nbsp;
      <% end %>

      <% if !current_page?(problems_path) %>
        <%= link_to "Problem list", problems_path %> | &nbsp;
      <% else %>
        <bold>Problem list</bold>  | &nbsp;
      <% end %>

      <% if !current_page?(new_problem_path) %> 
        <%= link_to "Add new problem", new_problem_path %> | &nbsp;
      .......

现在,当我导航到&#34;问题时,添加新问题&#34;我没有得到&#34; home&#34;与链接。

解决此问题的任何建议?

1 个答案:

答案 0 :(得分:1)

我认为你应该尝试一下:

<% if controller_name == "pages" %>
        <bold>Home</bold>  | &nbsp;
      <% else %>
          <%= link_to "Home", home_path %> | &nbsp;
      <% end %>