Rails and development - access to session data

I have a Rails application with integrated design. I am using a cookie store session. I need to store some data in a session every time someone signs up, for example. their user id. How can I do this using Devise?

Maybe there is some elegant way where I just don't need to do this, and I could access it using Devise.?

Thanks!

+6
ruby-on-rails session devise
source share
1 answer

You can use the "session" variable inside the controllers. Something like session[:some_value] = "some_value"

Also, Devise already has a user_id stored in the session. current_user A helper method can be used here.

Also make sure you read this, it has information about what to keep in the session or not. http://guides.rubyonrails.org/security.html

In addition, the cookie session store is usually only 4 KB in size, so you cannot store a lot of data in it or your application will start logging out.

+8
source share

All Articles