Question

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.

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top