Last active
October 3, 2015 22:17
-
-
Save nacengineer/2533050 to your computer and use it in GitHub Desktop.
Flash Messages with Bootstrap 2 and Rails 3.2.3
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 ApplicationHelper | |
include FeedbackHelper | |
# Your methods here | |
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
# 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 |
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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also check out this for more infomation. http://stackoverflow.com/a/9301461