I want to be able to transition pages from users/index to users/show

Error message
ActiveRecord :: RecordNotFound in UsersController # show
Couldn't find User with 'id' = #<User :: ActiveRecord_Relation: 0x00007f8292d25ef8>
Applicable source code


  Recommended setting
    <% = link_to "See the recommendation", user_path (@user)%>
    <% = link_to "Determine the guess", new_user_path%>


  Push men


class UsersController</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 User

When you check params by doing binding.pry at the show action of controller
Since id was "#
I don't think I can get it well, but I don't know where to fix it.
It was confirmed that the page can be transitioned if id is directly entered from users/index into url.

Supplemental information (FW/tool version etc.)

I don't know if you have the necessary files, but thank you.

  • Answer # 1

    @user = User.all If multiple users are imported, the value is not an instance of User, but a model called Relation.
    Also, Rails should be more sensitive to singular plurals. Let's be users.
    @users = User.all
    As for view, please take it out one by one.

    <% @ users.each do | user |%>
      # Display various users
      <% = link_to "See the recommendation", user_path (user)%>

    It is a feeling.