I am using Ruby on Rails 3.0.9 and jQuery 1.6.2 I am trying to implement an AJAX HTTP request handling JSON data with-in a partial template data rendered.
What I would like to make is render a partial template (performing the rendering process in a controller action and using the render_to_string RoR method, as well) and put the rendered HTML in that JSON data. However, I have some problem on parsing the JSON data with jQuery and I think because in the partial template there are " and ' characters that break the JSON format. In fact, if I render a “simple text” instead of the partial all works.
How can I solve this issue? What do you advice about?
P.S.: I think a similar issue is discussed in this topic…
It’s not exactly what you’re looking for, but you could use js.erb to update your views dynamically.
Tell the controller to respond to js format:
create action_name.js.erb in your controller’s view folder similar to this:
It doesn’t return JSON, instead it returns the complete rendered HTML of your partial. If you need to render a view file (without the leading underscore in the name), you’ll need to pass a
:fileoption and specify the extension of the file.