i'm trying to implement wysihml5 in a sinatra app using Activerecord.
The rich text editor works great and when i submit the form i got right html post to controller:
pry:> request.params
=> {"title" => "title text",
"content" => "<b>bold text</b><br><i>italic text</i>",
"_wysihtml5_mode" => 1
}
Then, i remove hash entry "_wysihtml5_mode" from request.params to create the db entry, then i convert content to json:
pry:> request.params.delete("_wysihtml5_mode")
=> 1
pry:> request.params["content"].to_json
=> "\"\\u003Cb\\u003Ebold text\\u003C/b\\u003E...
pry:> class.create(request.params)
The problem is i can't get my value back as begining:
pry:> class.last.content
=> "\"\\u003Cb\\u003Ebold text\\u003C/b\\u003E...
pry:> JSON.parse(class.last.content)
JSON::ParseError: 743: unexpected token at '"\\u003Cb\\u003Ebold text\\u003C/b\\u003E...
How could i get back this unicode charcters to their utf-8 style (i might be wrong, i m not comfortable with characters table). It seems that during convertion to json, a " is added at the begining:
"<b>bold => "\"\\u003Cb\\u003Ebold
This might be the problem? Any ideas?
italic text"}.to_json` returns valid json, but `"bold text
italic text".to_json` does not. – miah Aug 23 '13 at 15:10