So far I've got:
but is there definitive list, that can be used in place, such as in redirect_to path, :error => "Oh no!"
?
What are flash messages? A flash message is a way to communicate information with the users of your Rails application so they can know what happens as a result of their actions. Example messages: “Password changed correctly” (confirmation)
To implement flash messages in NodeJs with connect-flash module, you need to install the required dependencies using the command. Express: Required by the library connect-flash to run. Express-session: to create a session whenever a message is flashed, so that the user can be redirected to a particular page.
The flash hash is basically a variable which is populated with each controller/action request, and then is reset after the request has been performed. As Adilbiy Kanzitdinov has mentioned - it's set in the session hash : The flash provides a way to pass temporary objects between actions.
Hauleth is correct that you can use any symbol, but right now, :notice
and :alert
are the only ones you can pass directly into redirect_to
(according to flash.rb in Rails source), as you specifically mention:
redirect_to path, :error => "Oh no!" # Will not work
If you want a different flash type such as :error
(or :success
), you must pass those in through the :flash
key, like so:
redirect_to path, :flash => { :error => "Oh no!" }
For information on how to register your custom flash types so that, like :notice
and :alert
, you can pass them directly in to redirect_to
, see this StackOverflow Q&A: https://stackoverflow.com/a/3848759/995663
Update: According to this commit, it seems Rails 4 will make this easier by allowing you to register custom flash types by calling add_flash_types :error
in ApplicationController.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With