Skip to content

Instantly share code, notes, and snippets.

@gregkare
Last active April 27, 2018 16:51
Show Gist options
  • Save gregkare/542cf493bbfd4d1c6ded to your computer and use it in GitHub Desktop.
Save gregkare/542cf493bbfd4d1c6ded to your computer and use it in GitHub Desktop.
FlashHash

How to crash Rails > 4.1.0 in a pretty confusing way:

def index
  redirect_to new_post_url, flash: flash
end
NoMethodError:
 undefined method `stringify_keys' for #<ActionDispatch::Flash::FlashHash:0x00000006dd96f8>

flash is an instance of ActionDispatch::Flash::FlashHash. This code was weird but worked in versions before 4.1.0 because nothing was done to the FlashHash:

In 4.1.0 they're now stringifying the keys: https://github.com/rails/rails/commit/a668beffd64106a1e1fedb71cc25eaaa11baf0c1

ActionDispatch::Flash::FlashHash doesn't have a #stringify_keys method.

You only pass a flash if you actually want to pass a message around, as a string or hash:

def index
  redirect_to new_post_url, flash: "Some message"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment