0

我正在使用 bootstrap alert 来设置 rails flash 消息的样式,但我不知道为什么会这样

 def render_flash_msgs
    unless @_flash_rendered
        @_flash_rendered = true
        render 'shared/flash_msgs'
    end
 end

  # return html class for flash_key
  def bootstrap_class_for(flash_key)
     flash_key == :notice ? 'alert-info' : "alert-#{flash_key}"
  end

我不能发布图片,所以我只能发布 html 结果源

  <div id="flash">
  <div class="alert" title="Notice">
    <button class="close" data-dismiss="alert">×</button>
    <div>Post was successfully updated.</div>
  </div> 
  <!-- dont know why it showed again under the alert block -->
  <p id="notice">Post was successfully updated.</p>

编辑 : - - - - - - - - - - - - - - - - - - - - - - - - -- 这是我的表格

 = form_for @post do |f|
  - if @post.errors.any?
    #error_explanation
      h2 = "#{pluralize(@post.errors.count, "error")} prohibited this post from being saved:"
      ul
        - @post.errors.full_messages.each do |message|
          li = message

  .field
    = f.label :title
    = f.text_field :title
  .actions = f.submit 'Save'

这是我的 Flash 页面 -----------------------------------

#flash
  - flash.each do |type, message|
    .alert class=bootstrap_class_for(type)
      button.close data-dismiss="alert"
        | &times;
      div = message 
4

1 回答 1

0

听起来您的警报在布局和表单中显示一次。请向我们展示布局并发布_form部分内容。

于 2013-05-05T08:03:47.207 回答