views:

718

answers:

4

hi, i'm having problem to deal with charset in ruby on rails app, specificially in my templates. Code that comes from my database, works fine, but codes like ç ~ that are located in my views are not working. I added the following codes to my code

I added a function like that, but that still not working i have ç ~ codes in my application.rhtml that are not working.

before_filter :configure_charsets 
 # Configuring charset to UTF-8 def configure_charsets    
 headers["Content-Type"] = "text/html; charset=UTF-8"     
end

I added as well meta http-equiv html to utf-8 and a .htaccess parameter AddDefaultCharset UTF-8

That's still not working, any other tip?

+1  A: 

Is your application.rhtml file written in the correct character set? Make sure it's UTF-8, and not ISO-8859-1.

Curt Sampson
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
VP
That doesn't mean it's written in UTF-8. It just means it's telling the browser that it's in UTF-8. You have to tell your text editor to save using the UTF-8 character set.
Samir Talwar
+2  A: 

Is the text editor you're using to put the special characters into the file (either source or views) treating those characters as UTF-8? For example, if you're using TextMate, you can deliberately save a file as UTF-8. If for some reason you used a different encoding earlier (a default, perhaps), those UTF-8 characters might be getting transcoded at the code editing stage, so even if the rendering process is using UTF-8 throughout, it'll still not work.

Further, if you're using something from a shell, like vi, or whatever, is your terminal set up to accept UTF-8 as default? If you had it set to ISO-8859-1 or whatever, you'd get the same issue.

Peter Cooper
i doubled check it. I saved the file again as utf-8 encoding in my programmer notedpad but i'm still having this problem.
VP
A: 

So if the contents of your file are UTF-8, and the output is being interpreted as UTF-8, something in between is changing the data. Can give give us the the hex interpretation of the input bytes (anything non-ASCII will be at least two bytes in UTF-8) for one of your special characters, and the hex interpretation of the output byte or bytes? Perhaps we can figure out what the change is, and work back from there.

Curt Sampson
+1  A: 

Put this piece of code in your config (environment.rb) Rails::Initializer.run do |config| config.action_controller.default_charset = "iso-8859-1" end

THis will; do it.

ALso, remove the default charset line if any in layouts/application.html

satya