【发布时间】:2019-02-03 11:35:27
【问题描述】:
我正在使用 Gem 'Devise' 为我的页面设置用户和管理员。我创建了一个登录页面,要求用户首先登录,然后在成功登录后,我想将用户重定向到模型 Category 的主页,该主页将只显示产品类别列表。然而,我还没有找到正确的方法来做到这一点。这是我的路线文件:
Rails.application.routes.draw do
resources :categories
root to: 'pages#home'
devise_for :users
end
这是我在视图页面中的 home.html.erb 文件:
<h1>Login page</h1>
<% if current_user %>
<%= link_to 'Categories', category_path(@category) %>
<%= link_to 'Sign Out', destroy_user_session_path, method:
:delete %>
<% else %>
<%= link_to 'Sign Up', new_user_registration_path %>
<%= link_to 'Sign In', new_user_session_path %>
<% end %>
我收到一条错误消息:
ActionView::Template::Error
(No route matches {:action=>"show",:controller=>"categories", :id=>nil},
missing required keys: [:id]):
如何将视图Page的home.html.erb文件与的index.html.erb连接起来>类别视图?提前感谢您提供的任何帮助
【问题讨论】:
-
用
categories_path替换category_path(@category)
标签: ruby-on-rails ruby routes