Search code examples
ruby-on-railsinternet-explorerpostgresqlutf-8delayed-job

strange UTF-8 byte encoding issue with Rails, IE, PostgreSQL, delayed_job


I'm seeing a relatively strange (and hard to diagnose) error with a combination of IE8, Rails 3.0.3, PostgreSQL and delayed_job.

I have a text area on one of my pages, and in the controller I delay a message with delayed_job which includes an object which has the content from the text area:

SomeMailer.delay.send_message(message)

This works fine on Chrome, FF, Safari. However in IE8 only, and only when I actually enter text in the text area, and it looks like only when I enter a carriage return in the text area (I think), I get this error from the controller:

invalid byte sequence in UTF-8

This appears to me to be when delayed_job is serializing the job to the database via ActiveRecord, that it doesn't like the character encoding in the newline (\r\n). It's a bit hard to figure out because I don't know if this is an IE, Rails, delayed_job or Postgres issue.

Side Note: I'm getting this error locally, but it doesn't appear that this error appears on Heroku - so maybe they have their database configured better than I do?

Environment:

  1. Rails 3.0.3
  2. Ruby 1.9.2
  3. Postgres 8.4 - encoding UTF8, collation en_US.UTF-8
  4. delayed_job 2.1.4
  5. IE 8

Any thoughts would be appreciated.


Solution

  • Are you setting your encoding in the HTML that is being sent to IE8? e.g.:

    <!doctype html>    
      <head>
        <meta charset="utf-8">
      </head>
    

    It's possible that the other browsers are working around the missing information and assuming UTF-8 when encoding the data from your text area.