Is there a method for determining whether or not the session is a NEW session? For example. the first request of a session I want to be able to perform an action. Subsequent requests under the same session id, I do not want to execute the action. Thanks! Tom --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jan 2, 2008, at 12:33 PM, TomRossi7 wrote:> > Is there a method for determining whether or not the session is a NEW > session? For example. the first request of a session I want to be > able to perform an action. Subsequent requests under the same session > id, I do not want to execute the action. >I don''t know of a method, but you could do something like if session[:my_var].nil? # it''s a new session # do some funky stuff session[:my_var] = my_value end Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You could look if certain session attribute was set or not. In case it wasn''t, it was the first time you requested it and you could call that action and eventually set this session attribute for the next request: if session[:first_time].nil? your_action session[:first_time] = true end Regards TomRossi7 escribió:> Is there a method for determining whether or not the session is a NEW > session? For example. the first request of a session I want to be > able to perform an action. Subsequent requests under the same session > id, I do not want to execute the action. > > Thanks! > Tom > > > > >--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the responses Borja and Phillip! Those methods would definitely do what I want, I was just hoping their was a better way to do it without creating a new session variable. You would think there is a hook somewhere when the session id is created? -- Tom On Jan 2, 1:55 pm, Borja Martín <bor...-v796FXedN1GsTnJN9+BGXg@public.gmane.org> wrote:> You could look if certain session attribute was set or not. In case it > wasn''t, it was the first time you requested it and you could call that > action and eventually set this session attribute for the next request: > > if session[:first_time].nil? > your_action > session[:first_time] = true > end > > Regards > > TomRossi7 escribió: > > > Is there a method for determining whether or not the session is a NEW > > session? For example. the first request of a session I want to be > > able to perform an action. Subsequent requests under the same session > > id, I do not want to execute the action. > > > Thanks! > > Tom--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 1/2/08, TomRossi7 <tom-5bxIUPmzHicFraO2wh7vUA@public.gmane.org> wrote:> > Thanks for the responses Borja and Phillip! Those methods would > definitely do what I want, I was just hoping their was a better way to > do it without creating a new session variable. You would think there > is a hook somewhere when the session id is created?You will not burn in hell for creating additional session variables, especially an int. Some people (not me of course) stick entire ActiveRecord objects in their sessions without harm. Besides all that, aren''t _you_ the one creating the session id to start with? The line right below there is your opportunity to do your one-time-only stuff. -- Greg Donald http://destiney.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 -~----------~----~----~----~------~----~------~--~---
Hah! I''m not concerned with my eternal security, just trying to have beautiful code with minimal overhead. The session id is created by the rails framework and that is why I was thinking their may be a hook or attribute somewhere I could access (kinda like ActiveRecord''s new_record? method). --Tom On Jan 2, 5:09 pm, "Greg Donald" <gdon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 1/2/08, TomRossi7 <t...-5bxIUPmzHicFraO2wh7vUA@public.gmane.org> wrote: > > > > > Thanks for the responses Borja and Phillip! Those methods would > > definitely do what I want, I was just hoping their was a better way to > > do it without creating a new session variable. You would think there > > is a hook somewhere when the session id is created? > > You will not burn in hell for creating additional session variables, > especially an int. Some people (not me of course) stick entire > ActiveRecord objects in their sessions without harm. > > Besides all that, aren''t _you_ the one creating the session id to > start with? The line right below there is your opportunity to do your > one-time-only stuff. > > -- > Greg Donaldhttp://destiney.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 -~----------~----~----~----~------~----~------~--~---