As the title of the question asks, I am interested in knowing if there is any difference when using flash[:error]
, flash[:alert]
, and flash[:
:alert
and :notice
functionally differ from other keys you invent. FlashHash
provides convenience accessors for the two: flash.alert
, flash.notice
. Rails' preference for these two further rears its way into redirect_to
which will only accept :alert
, :notice
, or :flash
.
However, a commit in July 2012 to edge Rails allows the privilege of adding other flash types. Here's an example of adding custom flash types in Rails 4:
# app/controllers/application_controller.rb
class ApplicationController; add_flash_types(:error, :annoyance); end
# app/controllers/monopoly_controller.rb
class MonopolyController < ApplicationController
def chance
...
redirect_to haha_path, annoyance: "Go directly to jail. Do not pass Go. Do not collect $200."
end
end
# app/views/haha/index.html.erb
<%= annoyance %>