Implementation of “Remember me” in a Rails application

Ankit Singh

Total Post:341

Points:2389

Posted by  Ankit Singh
 1469  View(s)
Ratings:
Rate this:
My Rails-app has a sign in box with a "remember me" checkbox. Users who check that box should remain logged in even after closing their browser. I'm keeping track of whether users are logged in by storing their id in the user's session.

But sessions are implemented in Rails as session cookies, which are not persistent. I can make them persistent:


    class ApplicationController < ActionController::Base
      before_filter :update_session_expiration_date

      private

      def update_session_expiration_date
        options = ActionController::Base.session_options
        unless options[:session_expires]
          options[:session_expires] = 1.year.from_now
        end
      end
    end
But that seems like a hack, which is surprising for such common functionality. Is there a better way?

Answer

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.