Reputation: 906
Running into a strange problem. I was sure that it used to work and is fixed in this version (https://github.com/rails/rails/issues/1553). I have a simple controller
class MessagesController < ApplicationController
def create
@msg = Message.new(params[:message])
@msg.user_id = session[:user_id]
@msg.room_hash = session[:current_room_hash]
@msg.save!
end
end
A form that submitting it:
<%= form_for Message.new, :html => {:id => "post_submit_form", :remote => true} do |f|%>
<fieldset>
<%= f.text_area :message, :id => 'post' %>
<%= f.submit 'Post', :class => "button post" %>
</fieldset>
<% end %>
a create.js.erb file for rendering the html:
$('#pending_item').html(<%= escape_javascript(render(:partial => 'stream_item'))%>);
Using jquery 1.6.1 and latest rails.js I keep getting parsererror in firebug by binding to ajax:error. I think is a problem with escape_javascript as if it just do the following it works great:
$('#pending_item').html('<h2>hello</h2>');
I know that partial works as it is use repeatedly to display the when the page loads. Additionaly if I just have:
<h2>hello</h2>
in the partial I have the same parsererror
I am sure I am using 3.0.9 as it says this when i start the app:
Rails 3.0.9 application starting in development on http://0.0.0.0:3000
Any ideas?
Upvotes: 0
Views: 829
Reputation: 124439
You need to wrap your <%= escape_javascript(...) %>
part in quotes:
$('#pending_item').html("<%= escape_javascript(render(:partial => 'stream_item'))%>");
Upvotes: 2