L
L
lavezzi12015-09-02 03:17:19
Ruby on Rails
lavezzi1, 2015-09-02 03:17:19

Why can't find the user?

Hello. Following the instruction of the video lesson on codeschool ran into a problem. The situation is this:
There are users and there are articles. The models specify relationships, User has_many article and Articles belongs_to user. In routes we specify:

resources :users do
  resources :articles
end

Now we edit Articles_controller. The lesson says, you need to find users, do the following:
def get_user
  @user = User.find(params[:id])
end

before_filter :get_user to the very top.
I get the following Couldn't find user ='id'
How to be?
Now everything in my application is tied to current_user. But now I'm redoing it so that each user displays their own information.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vayladion Gognazdiak, 2015-09-02
@etspring

try

resources :users do
 member do
  resources :articles
 end
end

well, put get_user under private

B
Boris Penkovsky, 2015-09-02
@Able1991

resources :users do
  resources :articles
end

In this case, in the articles controller there will be params[:user_id], look at the server console, what are the parameters of the request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question