Rails 3.1 (rc4), AJAX and UTF-8
I believe this is OK, so I am creating a question that I have 开发者_高级运维the answer to for other peoples benefit. The problem:
I'm using a remote link to send a request for information and returning script containing that information. The data that comes back is for some reason encoded in ISO-8859-15 even though I have done everything I could find that would make Rails & Ruby use UTF-8.
show.coffee
$('#messages_messages').html("<%= escape_javascript(render 'show') %>")
# _show.html.erb will create output with characters such as åäö
The response contains a bunch of ?-characters instead of åäö.
For some reason this bug only happens when using the .coffee filename. This is my solution:
Don't use .coffee and the end of your filename. show.js.erb
$('#messages_messages').html("<%= escape_javascript(render 'show') %>");
# _show.html.erb will create output with characters such as åäö
No encoding errors.
精彩评论