Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

SessionTimeout: A Rails Plugin to handle short-term session timeouts

By Peter Cooper / October 2, 2006

SessionTimeout is a Rails plugin by Luke Redpath that makes enforcing short session times easy, like so:

class ApplicationController
	session_times_out_in 600, :after_timeout => :do_something

	def do_something
	  logger.info "HELLO, IVE TIMED OUT!"
	end
end

Luke explains:

With Rails built-in session options, you can set a specific session expiry time however in production mode this expiry time is set just the once. This is fine if you are setting your expiry time far in the future (and therefore you are likely to restart your server processes by that time) but if you want to set your timeout in the near future, your session expiry will soon be a date/time in the past - this will cause a new session to be created for every new request resulting in disaster.

Comments

  1. Luke Redpath says:

    Cool, thanks for the linkage. Don't forget you can also use Rails' time helpers for a more expressive timeout:

    session_times_out_in 10.minutes

Other Posts to Enjoy

Twitter Mentions