views:

509

answers:

1

I am using jQuery to do an ajax call to my controller, and everything is working perfectly, except I can't quite get the return value that I want.

Let's say I have a collection of items, and I have the partial:

/app/views/messages/_message.html.erb

I am trying to render it as a big string of text/html like so:

format.js { render_to_string :partial => "message", :collection => @messages}

However, this is rendering a view of some sort, because I'm getting and tags. Even if I change it to:

format.js { render_to_string :partial => "message", :collection => @messages, :layout => 'none'}

it still returns the same thing. Is this possible? I need to return it for jQuery to handle it, so I'm not sure if this can be done with rjs. Any help is appreciated.

+2  A: 

Have you tried just using render instead of render_to_string?

Also, the fact that you're using jQuery makes this slightly more complicated, if you were using prototype you could use rjs and do something like

page.replace_html('container_element', :partial => @messages)
jonnii
I don't want to replace the html of the container element, I want to append to it. I CAN use page.replace_html thanks to the jrails plugin
Mike Trpcic
Then you would use: page.insert_html :bottom, :partial => @messages
jonnii