Skip to content

Instantly share code, notes, and snippets.

@adrianpacala
Last active August 12, 2017 06:27
Show Gist options
  • Save adrianpacala/8db2212519a69ec68b609d23847d16f9 to your computer and use it in GitHub Desktop.
Save adrianpacala/8db2212519a69ec68b609d23847d16f9 to your computer and use it in GitHub Desktop.
Enumerable flash messages in Rails
<% 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 %>
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