Forum: Ruby on Rails Setting character encoding - do I do it with Rails or lightt

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-02-25 04:48
(Received via mailing list)
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
0091f92762685860109bbcb02edfdf27?d=identicon&s=25 Alain Ravet (Guest)
on 2006-02-25 10:41
(Received via mailing list)
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
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2006-02-25 11:45
(Received via mailing list)
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'
>     end

Argh, 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
6738e5c4f17822f7e163ba938344755d?d=identicon&s=25 Daniel (Guest)
on 2006-02-25 13:08
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
0091f92762685860109bbcb02edfdf27?d=identicon&s=25 Alain Ravet (Guest)
on 2006-02-25 20:40
(Received via mailing list)
> 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
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-02-26 02:20
(Received via mailing list)
On 2/25/06, Alain Ravet <arav2132@biz.tiscali.be> wrote:
>         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
>        @lists = ...
>
Just wanted to say this worked perfectly, thanks.
This topic is locked and can not be replied to.