0

好的,我会尽量具体一点。这是我的代码:

路线.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>

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

4

0 回答 0