-
-
Save mariozig/ed25e8fd0a5b0ee24c4e to your computer and use it in GitHub Desktop.
Flash messages / 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
# app/helpers/application_helper.rb | |
def twitterized_type(type) | |
case type | |
when :alert | |
"alert-block" | |
when :error | |
"alert-error" | |
when :notice | |
"alert-info" | |
when :success | |
"alert-success" | |
else | |
type.to_s | |
end | |
end | |
# app/views/layouts/application.html.haml | |
=render :partial => "shared/flash_messages", :locals => {:flash => flash} | |
# app/views/shared/_flash_messages.html/haml | |
- flash.each do |type, message| | |
%div.alert-message.fade.in{ "data-alert" => "alert", :class => twitterized_type(type) } | |
%a.close{:href => "#"} × | |
%p | |
= message |
Just missing a good 'ol spec test 👇
require 'spec_helper'
describe ApplicationHelper do
context "instance methods" do
describe "#twitterized_type" do
let(:twitter_flashes) do
{
:alert => 'alert-block',
:error => 'alert-error',
:notice => 'alert-info',
:success => 'alert-success'
}
end
it "returns the twitter-bootstrap version for each flash type" do
twitter_flashes.each do |flash_type, twitter_class|
helper.twitterized_type(flash_type).should == twitter_class
end
end
end
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From post: http://ruby.zigzo.com/2011/10/02/flash-messages-twitters-bootstrap-css-framework/