I want to create a simple one-line function (to be used by a
before_filter) that expires the session[:updated_at] data after twenty
minutes.
To be honest, if I knew Ruby a little more I wouldn't be asking this
question, but exactly how does the addition and the subtraction of
Time work in Rails? Are they treated as time variables, or integer
variables of some form?
I want to create a simple one-line function (to be used by a
before_filter) that expires the session[:updated_at] data after twenty
minutes.
To be honest, if I knew Ruby a little more I wouldn't be asking this
question, but exactly how does the addition and the subtraction of
Time work in Rails? Are they treated as time variables, or integer
variables of some form?
Would something like this work?
-----------------------------------
private
def expire_session
session[:updated_at]=nil if Time.now-session[:updated_at]<20.minutes
I think you want > rather than <.
end
You can always try these things in the application console (not
regular irb, because a lot of stuff like "minutes" requires
ActiveSupport [which you can load in irb, but it's easier to use the
Rails console]):
update = Time.now; until Time.now - update > 5.seconds;