I am doing a insertBefore in jQuery
$.post('/blah', { blah : "some data" }, function(response) {
$(response).insertBefore($this); $this.val(''); }, "script"); }
On Rails side, create.erb.js
'<div style="background-color:yellow;"><%= show_content %></div>'
This code works just fine until the output contains a ' which breaks the HTML rendering. Essentially the return string contains something like this
'<div ...>It's a beautiful day</div>'
I am on Rails 3.0.x and have tried various combinations of escaping unescaping on both Rails and Javascript and nothing works, any suggestion? I could change ' to " but that just shifts the problem to another character that will break.
EDIT
Ok, this is way more complicated that I thought but I found a solution after many trials and errors
On Rails side, create.erb.js
'<div style="background-color:yellow;"><%= raw(show_content.gsub(/'/, "%27")) %></div>'
jQuery
$.post('/blah', { blah : "some data" }, function(response) {
$(unescape(response)).insertBefore($this); $this.val(''); }, "script"); }
After many trials and errors, I found the solution, it’s not as simple as I hope but it works, see edited question for answer.