我正在使用Ruby on Rails 3.0.8。我想由Ryan貝茨按照教程found here.在Rails中不添加實際的HTML
這裏是我的所有代碼,然後我將解釋它在做什麼:
消息/ index.html.erb
<ul id="chat">
<%= render @messages %>
</ul>
<br/>
<%= form_for Message.new, :remote => true do |f| %>
<%= f.text_field :content %>
<%= f.submit "Send" %>
<% end %>
消息/ _message.html.erb(我用的內容標籤與純HTML)
<%= content_tag :li do %>
<%= content_tag :span, :class => "created_at" do %>
<%= message.created_at.strftime("%H:%M") %>
<% end %>
<%= message.content %>
<% end %>
*消息/ create.js.erb *
<% broadcast "/messages/new" do %>
$("#chat").append("<%= escape_javascript render(@message) %>");
<% end %>
$("#new_message")[0].reset();
我想這是所有相關的代碼。我的問題是,當我點擊「發送」時,它會將純html添加到我的「聊天」中。但是,如果我刷新頁面,那麼在我提交新消息之前,該HTML不再存在。
*之前刷新*
距離看這個,它看起來像HTML是完全不正確,跨度和李結束標記是不正確的。爲什麼會發生這種情況?但是當我刷新時,它看起來非常好。
*後刷新*
感謝大家提前!
這將讓我接受你的答案在5分鐘內。感謝您的快速和準確。 – ardavis 2011-06-16 21:01:10