对我的路线如何相互作用感到困惑

时间:2013-03-06 19:31:46

标签: ruby-on-rails-3 rails-routing

好的,我会尝试尽可能具体。这是我的代码:

的routes.rb

root to: "users#index"
match "/users/:id/about", to: "users#about", as: :about
match "/users/:id/blog", to: "users#blog", as: :blog
match "users/:id/contact", to: "users#contact", as: :user_contact
match "/contact", to: "static_pages#contact", as: :static_contact

resources :sessions, only: [:new, :create, :destroy]
resources :users do
  resources :portfolios do
    resources :pictures
  end
end

这是我的导航栏,其中包含主页上的所有链接:

 <nav>
    <ul class="sf-menu" id="nav">
      <li class="<%= "selected" if current_page?(root_path) %>"><%= link_to "home", root_path %></li>
      <li class="<%= "selected" if current_page?(about_path) %>"><%= link_to "about me", about_path %></li>
      <li><%= link_to "my portfolio" %>
        <ul>
          <% @user.portfolios.each do |portfolio| %>
            <li><%= link_to portfolio.name, user_portfolio_path(@user, portfolio) %></li>
          <% end %>
        </ul>
      </li>
      <li class="<%= "selected" if current_page?(blog_path) %>"><%= link_to "blog", blog_path %></li>
      <li class="<%= "selected" if current_page?(user_contact_path) %>"><%= link_to "contact", user_contact_path %></li>
    </ul>
  </nav>

当我从任何链接(主页,关于我,博客,联系人)链接到任何其他链接时,一切正常。例如,当我在about me页面(/ users / 8 / about)时,我可以链接到联系页面(users / 8 / contact)。问题是当我登陆投资组合页面(/ users / 8 / portfolio / 31)并尝试链接到about me页面时,例如,url变为:/ users / 31 / about而不是返回/ users / 8 /约。用户31不存在,但存在组合31。

0 个答案:

没有答案