I am using Rails 3.2.3 and Ruby 1.9.3. I have a model called called Post that accepts a title and a description. The front-end of the site receives information submitted through the back-end through an ajax request. When I fill out the form with, let's say
title: foo
content: foobar
and submit it, I am able to view data through the front-end without a problem.
However, whenever I submit non-utf8 data through the form, for example (mind the fancy quotes):
title: foo
content: “foobar”
When I try to render the form I get the following error:
ActionView::Template::Error (incompatible encoding regexp match (UTF-8 regexp with ASCII-8BIT string))
My .js.erb file looks like this:
$("#my_post").html('<%= escape_javascript(render :partial => 'post') %>');
I realize this is an issue with encoding, but I'm not sure how I should handle it the best way. I thought of several options:
- Strip out non-utf8 by using the iconv library -- do this via a before_save filter for every single model in my application
- Specifying at the top of the js that the document contains utf-8 (not sure this would work)
- Using
accept-charset="UTF-8"
in my form to force the browser to avoid submission of non-utf-8 content.
I'm not even sure these solutions would help and the most efficient way to do this would be. Thanks!