简体   繁体   中英

How can I connect my home page with other pages?

I am using the Gem 'Devise' in order to set users and admins for my page. I have created a log in page which requires the user to first sign in and then after the succesful log in I want to redirect the user to the home page of the Model Category , which is gonna be displaying just a list of categories of products. Yet, I have not found the proper way to do it. This is my routes file:

Rails.application.routes.draw do
  resources :categories
  root to: 'pages#home'
  devise_for :users
end

And this is my home.html.erb file inside the view pages :

<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 %>

I get an error saying:

 ActionView::Template::Error 
(No route matches {:action=>"show",:controller=>"categories", :id=>nil},
 missing required keys: [:id]):

How can I connect the home.html.erb file of the view Page with the index.html.erb of the Category view? Thanks in advance for any help provided

How can I connect the home.html.erb file of the view Page with the index.html.erb of the Category view?

If what you want is a link to view all categories, then why are you using a helper to view one singular category, category_path(@category) (and passing a non-existing @category too)? Instead, use this:

<%= link_to 'Categories', categories_path %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM