【问题标题】:Rails 3 flash notice stylingRails 3 Flash 通知样式
【发布时间】:2013-01-15 23:52:12
【问题描述】:

我正在使用 twitter bootstrap 来设置我的应用程序的样式。

这是我用于定义 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;
}

Flash 消息按预期显示,但始终显示 css 样式。如何隐藏样式以仅在显示 Flash 消息时显示。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.1 ruby-on-rails-3.2


    【解决方案1】:

    这是我用来显示我的 Flash 消息的助手:

    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
    

    关键是,如果没有,您不想显示 Flash 消息的容器。

    【讨论】:

      【解决方案2】:
      <% if flash[:notice] -%>
        <div class = "alert alert-success"><%= flash[:notice] %></div>
      <% end %>
      

      【讨论】:

        猜你喜欢
        • 2014-12-13
        • 2011-05-26
        • 2013-09-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-09
        • 1970-01-01
        • 2013-06-10
        相关资源
        最近更新 更多