It seems that when Devise logs a user in, only the user id is stored in the session.
This means that whenever calling current_user
will result in a SQL query (something like User.find(:id)
) to create the User object, which in many cases is unnecessary load.
For example, we may want to display the user's name in the top-right header, which is in the layout file and gets rendered in every response. For that we may just write current_user.name
, which causes a SQL query to the users table.
I really want to store some basic informations(such as the name and email) of the current user in the session, to avoid that extra SQL query.
What is the right solution to this problem?