ruby session expire


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  1. before_filter :session_expire
  2.  
  3. private
  4.  
  5. def session_expire
  6. if session[:user]
  7. session_length = 60*10 #10 Minutes for logged in users
  8. expire_time = session[:expire_time] || Time.now + 10
  9. if expire_time < Time.now
  10. reset_session
  11. flash[:notice] = "You have been logged out due to an extended period of inactivity"
  12. redirect_to :controller => 'welcome' , :action => 'index'
  13. else
  14. session[:expire_time] = Time.now + session_length
  15. end
  16. end
  17. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.