Rails View Encoding Issues

Rails View Encoding Issues

The culprit that was leaking non UTF-8 characters in my template was an innocuous meta tag for Facebook Open Graph

%meta{property: "og:url", content: request.url}

And when the request is non-standard, this causes the encoding issue. Changing it to

%meta{property: "og:url", content: request.url.force_encoding('UTF-8')}

made the trick.

Encoding issues in ActiveModel::Errors

you can alter the behaviour of almost everything in ruby (and rails).

Just create a new initialiser file inside config/initializers with something like this:

#monkeypatch_i18n.rb
(i don't know the exact path of active_model/errors.full_messages)
module ActiveModel
module Errors
def full_messages
#new logic
end
end
end

this overrides the default method.

regards,
juanma.

edit:
A more clean solution could be:

#lib/monkey_patch_i18n.rb
module ActiveModel
module Errors
def full_messages
#new logic
end
end
end

#config/initializers/init_i18n.rb
require "#{Rails.root}/lib/monkey_patch_i18n.rb"

Encoding problems in rails on ruby 1.9.1

I just had this as well so I think its worth having the correct answer.

The 2.8.1 MySql gem is not utf-8 friendly, so it sometimes will return UTF strings and lie to Rails, telling it that they are ASCII when in fact they are UTF-8. This makes things explode.

So: you can either monkey patch or get a compatible MySql gem. See: http://gnuu.org/2009/11/06/ruby19-rails-mysql-utf8/

Rails encoding error. HAML issue I think

tl;dr
Switched to the rdiscount parser and everything works now.

Longer Version:
I'm still not exactly sure what is going on but I know it's in the parser (rpeg-markdown gem).

Another bit of text on the production page had a weird Word apostrophe and that seemed to be the issue. If I wrapped both strings in :markdown filters it all worked, but if either wasn't in a filter I got the encoding error even though everything is utf-8.

I switched to rdiscount and now it works whether or not one (or both) of the blocks are wrapped in a :markdown filter.

Ruby on Rails - UTF8 encoding problems in MySQL from ActiveRecord

The problem was linked to my terminal. I imported the language list through it and I think this was the source of my encoding problem.

I downloaded Sequel Pro to manage my database and all of my data are not corrupted.



Related Topics



Leave a reply



Submit