K
K
Kolya2016-06-02 14:26:40
Ruby on Rails
Kolya, 2016-06-02 14:26:40

@user = User.find(params[:id]) doesn't return user id, why?

And user_find_by_id doesn't work either.
Controller:

def show
    @user = User.find(params[:id])
    @comments = Comment.where(post_id: @post)
  end

I call in the view:
= link_to @post.user.name, user_path(@user)
As a result, it returns the id of the post, why is that?
b6ed020794404c1bb3e747c8798ad2d7.PNG

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
CorbenDallass, 2016-06-02
@Dev_Kpug

Is it PostController? Then the error is that you are passing the post id to find, not the user.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question