Question:
I got the impression somewhere that a session instance was created
automatically when generating a rails app. However, to initialize my
session with some empty hashes, I had to precede the initialization
with an assignment to session, a la:
class ApplicationController < ActionController::Base
Problem:
I’m trying to trace my session hashes using logger.debug. I got a
complaint about using session’s each method, so I tried the following
statement in a method I defined in ApplicationController:
“‘session’ doesn’t respond to ‘each’” : “‘session’ undefined” )
The message I get is:
undefined method `each’ for #CGI::Session:0x3d52190
despite the fact that I’ve got a protection against executing the
session.each clause.
It seems to me that this error is propagated at compile time, so I need
a better way to handle possibly undefined methods. Any suggestions?
Well, I finally realized that I really did have a syntax error, so I
recoded the offending line in a somewhat verbose way as follows:
if ( defined?(session) && session.respond_to?("each") )
logger.debug "#{session.each {|p| ' ' + p.inspect}}"
else
if defined?(session)
logger.debug " Problem with session#each"
else
logger.debug " 'session' undefined"
end
end
I still do wonder about my initialization of session, however.
That’s what I used to do, but I got lost in the “syntax jungle”.
I still do wonder about my initialization of session, however, as
repeated here from by original post:
Question:
I got the impression somewhere that a session instance was created
automatically when generating a rails app. However, to initialize my
session with some empty hashes, I had to precede the initialization
with an assignment to session, a la:
class ApplicationController < ActionController::Base