ruby-on-railsdevisecookiestore

Why are my Rails sessions and cookies not persisting?


I have a Rails 4.0/Ruby 2.0 app with bare bones devise, and I added a feature to retain the main index page filter settings by way of an ajax call to the relevant controller, which stores them in session[:filter]. The session data (by way of CookieStore) is not persisting across requests as it ordinarily would. I've also tried using the cookies object and devise's user_session as well with the same result.

The devise session data works fine for authentication. I am making no other session assignments besides this. Is there something I should look for in <%= debug session %>?


Solution

  • I would verify if the ajax call is passing the authenticity token as a param. Rails clears the session if the authenticity token is not present in the ajax call, that comes from this line of code in the application_controller.rb:

    protect_from_forgery