Skip to content

Instantly share code, notes, and snippets.

@danteregis
Forked from roberto/parameterable_flash.rb
Created March 4, 2009 13:52
Show Gist options
  • Save danteregis/73843 to your computer and use it in GitHub Desktop.
Save danteregis/73843 to your computer and use it in GitHub Desktop.
module ParameterableFlash #ugly name
def self.included(base)
base.prepend_before_filter :catch_flash_from_params
end
def catch_flash_from_params
detected_flash_message = false
params.each do |key, value|
key = key.to_s
if key[/^flash_/] && !value.blank?
flash[key.gsub(/^flash_/, '').to_sym] = value
detected_flash_message = true
end
end
return redirect_to request.path if detected_flash_message
end
private :catch_flash_from_params
def redirect_away(url)
unless flash.blank?
url << "?" unless url.index("?").nil?
url << flash.collect do |key, value|
"flash_#{key}=#{value}" if value
end.compact.join('&')
end
flash.discard
redirect_to(url)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment