How to empty/destroy a session in rails?



  • 3 Answer(s)

    Reset_session method in a controller.

    reset_session
    

    Note: Resets the session by clearing out all the objects stored within and initializing a new session object.

    For more details check this link: http://api.rubyonrails.org/classes/ActionController/Base.html#M000668

    Answered on January 11, 2019.
    Add Comment

    Session in rails is a hash object:

    session.clear
    

    Specific keys have to be destroyed:

    session.delete(key)
    

    Regarding session.clear mentioned  session={} is not use.

    Answered on January 11, 2019.
    Add Comment

    Delete user session:

    session.delete(:user_id)
    

    Answered on January 11, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.