Reputation: 5141
I'm trying to setup my charset in a html view in a RoR application.
I configured already the charset by meta equiv tag:
**meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" **
It didn't work, so i tried to change my .htaccess (its a RoR application running under apache) but here is my problem. Normally i could use the following statement: AddType 'text/html; charset=ISO-8859-1' html
But the problem is that, as everybody knows, RoR has no "file extension" and that breaks this .htaccess solution. Anybody knows another way to set a charset in a layout template or view ?
Upvotes: 8
Views: 9694
Reputation: 1183
Just set :encoding => 'utf-8' after template name like this:
respond_to do |f|
f.pdf do
render :pdf => 'path_to_template_file', :encoding => 'utf-8'
end
end
Upvotes: 0
Reputation: 5141
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 tag and a .htaccess parameter AddDefaultCharset UTF-8
That's still not working, any other tip?
Upvotes: 2
Reputation: 27201
Have your Rails application set the Content-type
header, and then you won't need to worry about what Apache is doing.
response.headers['Content-type'] = 'text/html; charset=utf-8'
You may also want to add
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
to the page itself, so that if someone saves it to disk, it will load with the correct charset.
Upvotes: 13