Skip to content

Instantly share code, notes, and snippets.

@nacengineer
Last active October 3, 2015 22:17
Show Gist options
  • Save nacengineer/2533050 to your computer and use it in GitHub Desktop.
Save nacengineer/2533050 to your computer and use it in GitHub Desktop.
Flash Messages with Bootstrap 2 and Rails 3.2.3
module ApplicationHelper
include FeedbackHelper
# Your methods here
end
# put this in helpers directory
module FeedbackHelper
# For flash messages
def twitterized_type(type)
case type
when :alert then "alert alert-warning"
when :error then "alert alert-error"
when :notice then "alert alert-info"
when :success then "alert alert-success"
else type.to_s
end
end
def explain_errors(model)
if model.present? && model.errors.any?
html = ""
html << content_tag(:h4) do
<<-HERE_DOC
#{pluralize( model.errors.count, "error")} prohibited this
#{ model.class } from being saved:
HERE_DOC
end
html << content_tag(:ul) do
model.errors.full_messages.each {|msg|
concat(content_tag(:li, msg, class: 'text-error'))
}
end
html.html_safe
end
end
end
# app/views/layouts/application.html.haml
= render "layouts/flash_messages"
# layouts/_flash_messages.haml
- flash.each do |type, message|
%div{:class => "#{twitterized_type(type)} fade in" }
%div{:class => 'close', 'data-dismiss' => 'alert'}
%i.icon-remove-sign
= message
@nacengineer
Copy link
Author

Also check out this for more infomation. http://stackoverflow.com/a/9301461

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment