In respond_to
you can set flash[:notice]
like this
respond_to do |format|
format.html { redirect_to photo_path(photo), :notice => 'The photos was saved') }
format.xml { render :xml => photo, :status => :created}
end
I am trying to set flash[:success] with :success => "yay"
but it doesn't work.
Am I doing something wrong?
You should use redirect_to differently :
redirect_to photo_path(photo), :flash => { :success => "Yeepee!" }
The only flashes you can use directly are
Hope that helps
From Rails 4, you can directly use :success
in redirect_to
.
Just add this line:
# in app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
[...]
add_flash_types :error, :success, :info
[...]
Without this line, in respond_to, :notice produces flash, but :success doesn't work.
Hat tip to Milan Mondal's post for this!
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