我在使用twitter bootstrap的rails应用程序中使用AJAX crud操作。当我点击提交帖子然后显示成功的Flash消息,但是没有显示关闭按钮。
这是我的代码......
<div id="flash_notice" class="alert span6"></div>
这是我的表格......
<%= form_for(@post, :remote => true, :html => {:id => "prayer_form"}) do |f| %>
<div id= "post_errors" style="display:none"></div>
<p>
<%= f.select :title, options_for_select(["Relationship", "Family", "Health", "Personal", "Professional", "Education", "Tours & Travel", "Exams", "Job", "Society", "Career", "Marriage", "Relationship", "Friendship", "Event", "Success/Failure", "others"]), {:include_blank => "Select Prayer Category"}, {:multiple => false,:class => "required"} %>
</p>
<p>
<%= f.text_area :content, :rows => 5, :class=>"span12 required", :placeholder => "Create your prayer" %>
</p>
<p><%= f.submit "Add Prayer", :class=>"btn btn-primary"%></p>
<% end %>
这是我的create.js.erb
$("#post_errors").hide(300);
$("#flash_notice").html("<%= escape_javascript(flash[:notice] <button type='button' class='close' data-dismiss='alert'>×</button>) %>");
$("#flash_notice").show(300);
$(":input:not(input[type=submit])").val("");
$("#posts_list").html("<%= escape_javascript( render(:partial => "posts") ) %>");
的application.js
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .
正在显示闪光警报,但为什么我的关闭图标按钮未显示。请帮忙
答案 0 :(得分:1)
您无需将escape_javascript与真正的HTML代码混合使用。 HTML代码不需要通过Rails。
尝试替换此
$("#flash_notice").html("<%= escape_javascript(flash[:notice]
<button type='button' class='close' data-dismiss='alert'>×</button>) %>")
有了这个
$("#flash_notice").html("<%= escape_javascript(flash[:notice] %>" +
"<button type='button' class='close' data-dismiss='alert'>×</button>")