Last active
December 19, 2015 08:09
-
-
Save stevedev/5923320 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fun fact... | |
redirect_to some_path, notice: 'My notice' | |
redirect_to some_path, error: 'My error message' | |
# first will set a flash[:notice] while second will NOT set a flash[:error] | |
# vs: | |
flash[:notice] = 'My notice' | |
redirect_to some_path | |
flash[:error] = 'My error message' | |
redirect_to some_path | |
# Both will set the appropriate flash message. The reason why the difference? | |
# ActionController::Flash only handles alert and notice. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActionController #:nodoc: | |
module Flash | |
extend ActiveSupport::Concern | |
included do | |
delegate :flash, :to => :request | |
delegate :alert, :notice, :to => "request.flash" | |
helper_method :alert, :notice | |
end | |
protected | |
def redirect_to(options = {}, response_status_and_flash = {}) #:doc: | |
if alert = response_status_and_flash.delete(:alert) | |
flash[:alert] = alert | |
end | |
if notice = response_status_and_flash.delete(:notice) | |
flash[:notice] = notice | |
end | |
if other_flashes = response_status_and_flash.delete(:flash) | |
flash.update(other_flashes) | |
end | |
super(options, response_status_and_flash) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment