In Rails 3, you can pass has attributes directly to redirect_to
to set the flash. For example:
redirect_to root_path, :notice => "Something was successful!"
However, this only works with the :alert
and :notice
keys; if you want to use custom keys, you have to use a more verbose version:
redirect_to root_path, :flash => { :error => "Something was successful!" }
Is there any way to make it so that custom keys (such as :error
, above) can be passed to redirect_to
without specifying it in :flash => {}
?
In Rails 4 you can do this
class ApplicationController < ActionController::Base
add_flash_types :error, ...
and then somewhere
redirect_to root_path, error: 'Some error'
http://blog.remarkablelabs.com/2012/12/register-your-own-flash-types-rails-4-countdown-to-2013
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