Last active
August 12, 2017 06:27
-
-
Save adrianpacala/8db2212519a69ec68b609d23847d16f9 to your computer and use it in GitHub Desktop.
Enumerable flash messages in Rails
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
<% flash.now[:alert] = 'This an example alert message.' %> | |
<% flash.now[:error] = 'This an example error message.' %> | |
<% flash.now[:notice] = 'This an example notice message.' %> | |
<% flash.now[:success] = 'This an example success message.' %> | |
<% flash.now[:secret] = 'This will not be shown.' %> | |
<% flash.now[:cool] = true %> | |
<% flash_messages.each do |type, message| %> | |
<div class="flash-<%= type %>"><%= message %></div> | |
<% end %> |
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
class ApplicationController < ActionController::Base | |
protect_from_forgery with: :exception | |
concerning :Flash do | |
included do | |
add_flash_types :error, :success | |
helper_method :flash_messages | |
end | |
def flash_messages | |
Hash[self.class._flash_types.map { |type| [type, send(type)] }] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment