Thursday, September 2, 2010

[Rails] controller failing to read flash

I'm seeing some pretty strange behavior from the flash in my rails
2.3.8 app. I set the flash in a request, and then redirect. In the
next request (the one redirected to), accessing the flash returns an
empty hash, but the flash is stored and visible in the session.

(rdb:21) session
{:user_credentials=>"...", :session_id=>"...", :user_credentials_id=>1, :flash=>{:notice=>"Twitter
status updated"}, :_csrf_token=>"..."}
(rdb:21) session[:flash]
{:notice=>"Twitter status updated"}
(rdb:21) flash
{}

Looking at the source for flash in actionpack-2.3.8/lib/
action_controller/flash.rb,
the difference is that the key is stored as a string and not a symbol.
How could that disparity occur?

# Access the contents of the flash. Use <tt>flash["notice"]</tt> to
# read a notice you put there or <tt>flash["notice"] =
"hello"</tt>
# to put a new one.
def flash #:doc:
if !defined?(@_flash)
@_flash = session["flash"] || FlashHash.new
@_flash.sweep
end

@_flash
end


Thanks!

Andrew

--
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@googlegroups.com.
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate