Pickaxe 246 is not only weak, but appears to be just wrong by saying:
if session[‘lastaccess’]
which doesn’t check that lastaccess is infact a hash key to begin with.
However, when I try a .has_key?, I get a failure with that (the above
fails as I expect also). So what gives? Is this just broken, or am I
not seeing an undocumented step that should be obvious to any
clairvoyent that dares use this?
I also don’t get enough from the core/classes/CGI/Session.html, which
does’t give good example of use of session, but rather only of starting
a session…all evidence that perhaps this tool never actually ever got
used…???
The way I’m trying to use this now is to initialize the session in a
class method in my user object, and then always retrieve a class
variable version of the session in the instantiator of the object. I am
using all defaults, and I don’t close the session in the class object,
but merely execute update before letting go of the local scope. Then
when I try to retrieve the session it just isn’t there. Perhaps because
it doesn’t see the session cookie yet or something.
Perhaps I need to just hold onto my created @Session value until
following sessions…
Okay, I appear to be creating the persistence file in
/tmp/somerandomyname, and it has the right hashy pair in it, but when I
restart the page independently, it doesn’t get that information in my
session. Again, I am taking all the defaults, so perhaps I’m missing a
requirement here, but I’m presuming it should see the right file in tmp
from a cookie that it creates in the browser, right? Anyway, once the
file is created, it apparently is not read. Am I doing this right, or
am I perhaps misunderstanding?
You’re right. I miscoded my copy. Okay, my apologies. Still, it
would be nice to have more examples. Can anyone point me to some?
Rails?
Not really, though I am accessing active record in here, but I’m
presuming that should not affect it. This was written in plain ruby,
and then I decided to add a rails configuration tool. Anyway, I think I
made headway when I realized ‘new_session’ => true might be the default.
Now running it with false I get:
trace user_name: campanolix
trace @Session: CGI::Session
/usr/lib/ruby/1.8/cgi/session.rb:265:in initialize_without_cgi_reader': session_key_session_id’ should be supplied (ArgumentError)
from
/var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cgi_ext/session.rb:39:in
`initialize’
…
so I presume that means I cannot run with just all defaults. I’m using
the online example with ‘user_name’, but presumably session_key is
independent of my user name. I was presuming it would all be handled
with the cookie…? Perhaps I’m only demonstrating how confused I am.
And I just tried supplying a session key, and that leaves me with the
same diagnostic, but oddly it names my session key that it claims I need
to name:
/usr/lib/ruby/1.8/cgi/session.rb:265:in initialize_without_cgi_reader': session_keyccr’ should be supplied (ArgumentError)
from
/var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/cgi_ext/session.rb:39:in
`initialize’
One thing I also notice it I’m using stuff from what might be considered
a rails area (action_controller). Presumably this is not a problem…?
But I specify my ‘ccr’ key in the initialization, and then I specify it
again to initialize when I don’t see an instantiated session variable.
Result is still I don’t get my ‘user_name’ value up from the persistence
file.
Rails?
Not really, though I am accessing active record in here, but I’m
presuming that should not affect it. This was written in plain
ruby, and then I decided to add a rails configuration tool. Anyway,
I think I made headway when I realized ‘new_session’ => true might
be the default. Now running it with false I get:
You were asking for examples of use. Rails 1.x uses CGI::Session…
You were asking for examples of use. Rails 1.x uses CGI::Session…
Thank you. I’m looking at that now.
Looks like I need to find the way to make my eruby .rhtml files take
stuff from CGI objects like the cookies. Presumably they just ignore
it, since it is kindof foreign, and so I don’t get cookies set.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.