Question

I'm using Ruby on Rails 3.0.8. I'm trying to follow the tutorial by Ryan Bates found here.

Here is all of my code, then I'll explain what it's doing:

messages/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 %>

messages/_message.html.erb (I'm using content tags vs. pure html)

<%= content_tag :li do %>
  <%= content_tag :span, :class => "created_at" do %>
    <%= message.created_at.strftime("%H:%M") %>
  <% end %>
  <%= message.content %>
<% end %>

* messages/create.js.erb *

<% broadcast "/messages/new" do %>
  $("#chat").append("<%= escape_javascript render(@message) %>");
<% end %>

$("#new_message")[0].reset();

I think that's all of the relevant code. My problem is that when I click 'Send', it's adding the pure html to my 'chat'. But if I refresh the page, that html is no longer there until I submit a new message.

* Before Refresh *

enter image description here

Just from looking at this, it looks like the html is completely incorrect, the ending tag for span and li aren't right. Why would this be happening? But when I refresh, it looks pretty much fine.

* After Refresh *

enter image description here

Thanks everyone in advance!

Was it helpful?

Solution

escape_javascript broke in Rails 3.0.8 -- upgrade to Rails 3.0.9 (which came out today) to resolve the issue.

http://weblog.rubyonrails.org/2011/6/16/ann-rails-3-0-9-has-been-released

(The SafeBuffer issues mentioned in the release announcement's "Changes" section has to do with escape_javascript)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top