2013-01-15 110 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 %>