我正在使用bootstrap警报来设置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"
| ×
div = message
答案 0 :(得分:0)
听起来您的提醒会在布局中显示一次,而在表单中显示一次。请向我们展示布局并发布_form
部分。