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 end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Aug-20 12:44 UTC
Re: Time expiration code
Hi -- On Mon, 20 Aug 2007, Taro wrote:> > 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.minutesI think you want > rather than <.> endYou 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;?> puts "waiting..."; sleep 1; end; puts "done" waiting... waiting... waiting... waiting... waiting... done I think there are plugins that do more fine-grained and featureful observing for you, but anyway, that''s the basic idea. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> I think you want > rather than <. > > > endWhoops, yes you''re right about that. Regardless, if Time.now- session[:updated_at] works, than I really have nothing to worry about. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---