Rails and Devise - Access session data

14,632

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

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

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

Also cookie session store is usually only 4k in size, so you can't store a lot of data in them or your app will start to error out.

Share:
14,632
Jasdeep Singh
Author by

Jasdeep Singh

your friendly neighbourhood ruby & javascript guy. projects: http://github.com/jasdeepsingh/rainforest http://github.com/metaware/trakio http://metaware.github.io/angular-invoicing/

Updated on June 04, 2022

Comments

  • Jasdeep Singh
    Jasdeep Singh almost 2 years

    I have a Rails app with devise integrated. I'm using the Cookie Store session. I need to store some data in the session everytime someone signs in, Eg. their user id. How can i do so with Devise?

    May be there is some elegant way where i just dont need to do that and could access it with Devise itself.?

    Thanks!