2013-05-06 57 views
0

我在我的軌道應用程序與twitter引導中使用AJAX crud操作。當我點擊提交帖子,然後顯示成功的Flash消息,但隨着關閉按鈕不顯示。警告關閉按鈕不顯示在軌道上的紅寶石jquery .html()

這裏是我的代碼...

<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'>&times;</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

什麼是您的application.js是什麼樣子?你可以請發佈你的代碼示例 – Uchenna 2013-05-06 10:30:22

回答

1

您不需要將escape_javascript與真正的html代碼混合。 HTML代碼不需要經過Rails。

嘗試更換此

$("#flash_notice").html("<%= escape_javascript(flash[:notice] 
<button type='button' class='close' data-dismiss='alert'>&times;</button>) %>") 

有了這個

$("#flash_notice").html("<%= escape_javascript(flash[:notice] %>" + 
"<button type='button' class='close' data-dismiss='alert'>&times;</button>") 
+0

謝謝:)現在工作 – SoftwareGeek 2013-05-06 11:01:33

+0

@ user2354217,這很好。原因是Rails將你的html轉換爲純文本的「安全」html。 – 2013-05-06 11:02:47

+0

,但我得到了一個問題,如果我關閉閃光消息,並再次創建帖子,則不顯示閃光消息。它需要刷新頁面 – SoftwareGeek 2013-05-06 11:06:34