New Session?

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

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 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ó:

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

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.

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