E
E
eldar_web2017-11-21 21:30:10
Ruby on Rails
eldar_web, 2017-11-21 21:30:10

What is more civilized to write in Ruby on Rails: @current_user.id or session[:user_id]?

Question about the cultural code.
After authorization, @current_user is given from the application controller.
There is also session[:user_id].
That's when you have to write the id of the current user, then I don’t know which one to choose:
@current_user.id or session[:user_id]
Which one is better?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
IgorVol, 2017-11-22
@IgorVol

In session, you don't know what the id is.
In current_user you have the id of the user that is initialized (exists in the database)
Use current_user

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question