-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added :alert to FLASH_MESSAGE_TYPES. Using define_method instead of h…
…ard coding methods names. Using enumerable's any? method for method, flash_message_set?
- Loading branch information
Showing
1 changed file
with
4 additions
and
16 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,13 @@ | ||
module FlashMessageConductor | ||
FLASH_MESSAGE_TYPES = [ :error, :notice, :message ] | ||
FLASH_MESSAGE_TYPES = [ :alert, :error, :notice, :message ] | ||
|
||
module ControllerHelpers | ||
def add_error(msg) | ||
flash[:error] = msg | ||
end | ||
|
||
def add_notice(msg) | ||
flash[:notice] = msg | ||
end | ||
|
||
def add_message(msg) | ||
flash[:message] = msg | ||
FLASH_MESSAGE_TYPES.each do |message_type| | ||
define_method("add_#{message_type.to_s}") { |message| flash[message_type] = message} | ||
end | ||
|
||
def flash_message_set? | ||
flash_set = false | ||
FLASH_MESSAGE_TYPES.each do |key| | ||
flash_set = true unless flash[key].blank? | ||
end | ||
return flash_set | ||
FLASH_MESSAGE_TYPES.any? { |key| flash[key].present? } | ||
end | ||
end | ||
end |