Created
December 25, 2012 10:40
-
-
Save Heimdell/4372593 to your computer and use it in GitHub Desktop.
Flash helper library
This file contains 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 FlashHelper | |
[:success, :info].each do |kind| | |
define_method "flash_#{kind}" do |options = {}| | |
msg = options[:message] || kind | |
flash_notice message: msg, kind: kind, now: options[:now] | |
end | |
end | |
def flash_error(options = {}) | |
msg = options[:message] || :error | |
now = options[:now] || true | |
flash_notice message: msg, kind: :error, now: now | |
end | |
def flash_notice(options = {}) | |
msg = options[:message] || :notice | |
msg = flash_translate msg if msg.is_a?(Symbol) | |
kind = options[:kind] || :notice | |
if options[:now] | |
flash.now[kind] = msg | |
else | |
flash[kind] = msg | |
end | |
end | |
def flash_translate(key) | |
scope = [:flash, :controllers] | |
scope += params[:controller].split('/') | |
scope << params[:action] | |
t(key, scope: scope) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment