Skip to content

Instantly share code, notes, and snippets.

@roberto
Created March 4, 2009 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save roberto/73820 to your computer and use it in GitHub Desktop.
Save roberto/73820 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 << "?" if 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