Search code examples
ruby-on-rails-3respond-to

How to set custom flash with respond_to in Rails


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?


Solution

  • You should use redirect_to differently :

    redirect_to photo_path(photo), :flash => { :success => "Yeepee!" }
    

    The only flashes you can use directly are

    • :notice
    • :alert
    • :error

    Hope that helps