Pat Maddox
2006-Feb-25 03:45 UTC
[Rails] Setting character encoding - do I do it with Rails or lighttpd?
I have a page which validates "tentatively," because the validator uses the default character encoding. None was specified apparently, so it falls back to UTF-8. How and where do I specify the character encoding? Pat
Alain Ravet
2006-Feb-25 09:38 UTC
[Rails] Re: Setting character encoding - do I do it with Rails or lighttpd?
Pat> I have a page which validates "tentatively," because the validator > uses the default character encoding. None was specified apparently, > so it falls back to UTF-8. How and where do I specify the character > encoding?In layouts/application.html (f.ex), you can add: <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> ... If you use AJAX and partial rendering, you may have to specify it through headers, in order for special international characters to render correctly : def update_positions @lists = ... @headers["Content-Type"] = "text/html; charset=utf-8" render :partial => ''lists'' end Alain
Xavier Noria
2006-Feb-25 10:43 UTC
[Rails] Re: Setting character encoding - do I do it with Rails or lighttpd?
On Feb 25, 2006, at 10:38, Alain Ravet wrote:> If you use AJAX and partial rendering, you may have to specify it > through headers, in order for special international characters to > render correctly : > > def update_positions > @lists = ... > @headers["Content-Type"] = "text/html; charset=utf-8" > render :partial => ''lists'' > endArgh, I missed that detail in my AJAX actions, which are called as components as well. Since all my application is UTF-8 setting the header could be done for all actions, would it be clean to set that header with a filter in application.rb provided my program only serves XHTML? If that''s right, is the META element still needed? Maybe it doesn''t hurt as long as they coincide? -- fxn
Daniel
2006-Feb-25 12:08 UTC
[Rails] Re: Setting character encoding - do I do it with Rails or li
Pat Maddox wrote:> I have a page which validates "tentatively," because the validator > uses the default character encoding. None was specified apparently, > so it falls back to UTF-8. How and where do I specify the character > encoding?This works for me app/constrollers/application.rb: class ApplicationController < ActionController::Base before_filter :set_charset def set_charset @headers["Content-Type"] = "text/html; charset=iso-8859-1" end end // Daniel -- Posted via http://www.ruby-forum.com/.
Alain Ravet
2006-Feb-25 19:38 UTC
[Rails] Re: Setting character encoding - do I do it with Rails or li
> class ApplicationController < ActionController::Base> before_filter :set_charset > def set_charset > @headers["Content-Type"] = "text/html; charset=iso-8859-1" > end > end Great tip. AFAIK, this is the only way to make in_place_edit work with special characters, as the methods that return the partial are generated by Rails, and we can''t access them. How come Rails doesn''t do this by default? Alain
Pat Maddox
2006-Feb-26 01:19 UTC
[Rails] Re: Setting character encoding - do I do it with Rails or lighttpd?
On 2/25/06, Alain Ravet <arav2132@biz.tiscali.be> wrote:> Pat > > > I have a page which validates "tentatively," because the validator > > uses the default character encoding. None was specified apparently, > > so it falls back to UTF-8. How and where do I specify the character > > encoding? > > In layouts/application.html (f.ex), you can add: > > <head> > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> > ... > > > > > If you use AJAX and partial rendering, you may have to specify it > through headers, in order for special international characters to render > correctly : > > def update_positions > @lists = ... > @headers["Content-Type"] = "text/html; charset=utf-8" > render :partial => ''lists'' > end > > Alain > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Just wanted to say this worked perfectly, thanks.