You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
I'm upgrading a Rails 2.3 app to Rails 3.0 and intend to run both frameworks in production for a time to manage the transition. As such, I can have requests served by either 2.3 or 3.0. If I create a new session under Rails 3.0 and then try to read values in the flash under Rails 2.3 I get an error:
undefined method `each' for #<ActionDispatch::Flash::FlashHash:0x007fc58a9113e0>
/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rails_4_session_flash_backport-0.2.0/lib/rails_4_session_flash_backport/rails2/flash_hash.rb:50:in `block in new_from_session'
/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rails_4_session_flash_backport-0.2.0/lib/rails_4_session_flash_backport/rails2/flash_hash.rb:45:in `new_from_session'
/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rails_4_session_flash_backport-0.2.0/lib/rails_4_session_flash_backport/rails2/flash_hash.rb:26:in `from_session_value'
/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/rails_4_session_flash_backport-0.2.0/lib/rails_4_session_flash_backport/rails2/flash_hash.rb:62:in `flash'
To fix that, I modified rails2/flash_hash.rb to test whether what is in the Hash is a Rails 3.0 FlashHash
def self.new_from_session(flashes)
new.tap do |flash|
# Rails 3.0
if flashes.is_a?(ActionDispatch::Flash::FlashHash)
flashes = flashes.instance_variable_get(:@self)
end
flashes.each do |key, value|
flash[key] = value
flash.discard key
end
end
end
This works for my specific use case, but I was unsure as to how to add a test for that scenario? Also, whether there are ramifications elsewhere that I've overlooked.
Happy to PR with a bit of help. :)
Thoughts?
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I'm upgrading a Rails 2.3 app to Rails 3.0 and intend to run both frameworks in production for a time to manage the transition. As such, I can have requests served by either 2.3 or 3.0. If I create a new session under Rails 3.0 and then try to read values in the
flash
under Rails 2.3 I get an error:To fix that, I modified
rails2/flash_hash.rb
to test whether what is in theHash
is a Rails 3.0FlashHash
This works for my specific use case, but I was unsure as to how to add a test for that scenario? Also, whether there are ramifications elsewhere that I've overlooked.
Happy to PR with a bit of help. :)
Thoughts?
The text was updated successfully, but these errors were encountered: