I get an error when I try to go to users index from posts/index

Error message
ActionController :: UrlGenerationError in Users # index
/app/views/users/index.html.erb where line # 3 raised:
No route matches {: action =>"show",: controller =>"users",: id =>nil},

 missing required keys: [: id]
Applicable source code


      <% if user_signed_in?%>
          <% = link_to "Logout", destroy_user_session_path, method:: delete%>
          <% = link_to 'post', new_comment_path%>
      <% else%>
          <% = link_to "Login", new_user_session_path%>
          <% = link_to "new registration", new_user_registration_path%>
      <% end%>
        <% = link_to 'search', comments_path%>
      <% = link_to "Reminder setting", users_path%>


  Recommended setting
    <% = link_to "See the recommendation", user_path%>
    <% = link_to "Determine the guess", new_user_path%>
class User</pre>
<pre><code data-language = "model">class Member</pre>
<pre><code data-language = "model">class Favorite</pre>
<pre><code data-language = "routes">Rails.application.routes.draw do
  devise_for: users
  resources: users
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
  resources: posts, only: [: index]
  resources: comments, only: [: index,: new,: create,: show,: destory,: edit] do
    resources: likes, only: [: create,: destroy]
  resources: favorites, only: [: create,: destroy,: edit,: update]
  root to: 'posts # index'
class UsersController  []})

Under rails routes, there is an error where id is in the urlpattern, and if there is no error, you can see where no error occurs
I tried setting user_path (@user) to users_path (@user) or users/index in posts/index, but it couldn't be solved.

Supplemental information (FW/tool version etc.)

Please provide more detailed information here.

  • Answer # 1

    You seem to have found what the problem is.

    You need user_path (@user) or user_path (user), but you can't just write that, @user and user must be defined before that.
    <% = link_to "See the recommended person", user_path%>Who is the recommended person you want to see?

    Normally index displays a list. However, the index of UsersController does not extract the users that should be listed
    It is common to pass users/index as@users = User.all.
    Loop as@ user.each do | user |, and in that, try<% = link_to "See the recommendation", user_path (user)%>Please