Created
March 9, 2013 23:09
-
-
Save sergey-alekseev/5126200 to your computer and use it in GitHub Desktop.
Rails pretty flash messages with Twitter Bootstrap
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
# See http://twitter.github.com/bootstrap/components.html#alerts | |
# | |
# USAGE: | |
# flash.now[:info] = { title: 'New flash messages! ', body: 'Just add :info, :success, :warning or :error.' } | |
# redirect_to root_path, warning: 'You should use :success and :error instead of :notice and :alert' | |
# | |
# in application_controller.rb | |
def pretty_flash(name, msg) | |
msg_content = if msg.is_a?(String) | |
msg | |
elsif msg.is_a?(Hash) | |
content_tag(:strong) { msg[:title] } + msg[:body] | |
else | |
nil | |
end | |
# HACK: override devise :notice and :alert messages | |
name = 'success' if name.to_sym == :notice | |
name = 'error' if name.to_sym == :alert | |
if msg_content | |
content_tag(:div, class: "alert alert-#{name}") do | |
content_tag(:button, type: 'button', class: 'close', data: { dismiss: 'alert' } ) { '×'.html_safe } + | |
msg_content | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment