Rails: tracking user id

In my Rails application, I have a login page. After this user logs in, which is best for my application to continue tracking the person who is logged in. For example, if a user navigates to different pages, my controllers / actions will lose track of that user unless I continue to pass a variable between each page that the user visits. Is there a better way to do this? Should I use a variable sessions?

+5
source share
3 answers

Yes, sessions are exactly what you are looking for.

session["user_id"] = user_id

And to get the current user on another page (if your model is called User):

@current_user = User.find(session["user_id]")
+7
source

Think hard on the plugin to manage this.

There are several, for example, calm authentication .

It gives functionality current_userand logged_in?.

+4
source

There are some great stones that do this.

+2
source

All Articles