Hope someone will help me 🙂
So i was having problems with utf8 encoding, when using utf8 chars in my views, for example, from db..
I got this error:
incompatible character encodings: ASCII-8BIT and UTF-8
And btw, it wasnt a problem wih coding from db..
Anyway, I found the solution for my problem, and it was, to change method in
Ruby193\lib\ruby\gems\1.9.1\gems\activesupport-3.2.6\lib\active_support\core_ext\string\output_safety.rb
The method i changed was “concat”. So i changed this method:
def concat(value)
if !html_safe? || value.html_safe?
super(value)
else
super(ERB::Util.h(value))
end
end
alias << concat
to this:
def concat(value)
value = (value).force_encoding('UTF-8')
if !html_safe? || value.html_safe?
super(value)
else
super(ERB::Util.h(value))
end
end
alias << concat
But ofcourse its a bad idea, since, the app wont work on other servers..
So i want to override this method from my initializers, so i created:
config/initializers/utf8_fix.rb
with this code:
module ActiveSupport #:nodoc:
class SafeBuffer < String
def self.concat(value)
value = (value).force_encoding('UTF-8')
puts "--------------------------------"
puts "Loaded concat in utf8fix.rb"
puts "--------------------------------"
if !html_safe? || value.html_safe?
super(value)
else
super(ERB::Util.h(value))
end
end
alias << concat
end
end
But it seems that it dosnt override the default method. So can someone tell me, what am i doing wrong?
As “concat” is not class method i dosnt need self before it, so that was my problem..
Solved changing:
to: