2013-01-15 48 views
2

我使用twitter bootstrap來設計我的應用程序。Rails 3 Flash通知樣式

這是用來定義閃光MSG我的控制器的操作:

def generate_rating_set 
    redirect_to "/", :flash => { :notice => "New Set Successfully Created." } 
end 

和我認爲

<div class="alert alert-success"><%= flash[:notice] %></div> 

和我的CSS

.alert { 
    font-weight: bold; 
    -moz-border-radius: 4px 4px 4px 4px; 
    -webkit-border-radius: 4px 4px 4px 4px; 
    border-radius: 4px 4px 4px 4px; 
    margin-bottom: 18px; 
    padding: 12px 25px 12px 24px; 
    -moz-box-shadow: 3px 3px 1px 1px #CCCCCC; 
    -webkit-box-shadow: 3px 3px 1px 1px #CCCCCC; 
    box-shadow: 3px 3px 1px 1px #CCCCCC; 
} 
.alert-success { 
    background-color: #66E167; 
    border-color: #D6E9C6; 
    width: 280px; 
    color: black; 
    padding-top: 20px; 
} 

快閃消息顯示爲預期,但是CSS樣式始終顯示。如何隱藏樣式才能在顯示閃光消息時才顯示。

回答

3

這裏有一個幫手我用它來顯示我的提示信息:

def show_flash(options = {}) 
    output = ActiveSupport::SafeBuffer.new 

    [:alert, :notice].each do |message| 
     output << content_tag(:p, class: [message, options[:class]], tabindex: '0') do 
      flash[message] 
     end if flash[message].present? 

     flash[message] = nil 
    end 

    output 
end 

的一點是,你不希望如果有沒有顯示提示信息的容器。

4
<% if flash[:notice] -%> 
    <div class = "alert alert-success"><%= flash[:notice] %></div> 
<% end %>