Forum: Ruby on Rails html special chars

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.
Damian R. (Guest)
on 2007-06-19 22:47
Hi, i have a database with data that contains special html chars ... for
example, i may have names like "damián" "guzmán" and they get displayed
like "dami?n" and "guzm?n" in the browser, i need a render function that
allow me to convert those names to the html version ("damián" and
"guzmán") before display them ... any ideas will be most welcome
... thanks
Bob S. (Guest)
on 2007-06-19 23:03
(Received via mailing list)
On 6/19/07, Damian Rr <removed_email_address@domain.invalid> wrote:
>
> Hi, i have a database with data that contains special html chars ... for
> example, i may have names like "damián" "guzmán" and they get displayed
> like "dami?n" and "guzm?n" in the browser, i need a render function that
> allow me to convert those names to the html version ("dami&aacute;n" and
> "guzm&aacute;n") before display them ... any ideas will be most welcome
> ... thanks

Why not just declare your output encoding to match the encoding of the
data in your database? Or better yet, convert the data in the database
to UTF-8, which all modern browsers support and which Rails sets as
default output encoding.

HTML entities are handy for use in literals in your source code, but
aren't really appropriate for your data in this case.
Damian R. (Guest)
on 2007-06-25 18:22
Bob S. wrote:
> On 6/19/07, Damian Rr <removed_email_address@domain.invalid> wrote:
>>
>> Hi, i have a database with data that contains special html chars ... for
>> example, i may have names like "dami�n" "guzm�n" and they get displayed
>> like "dami?n" and "guzm?n" in the browser, i need a render function that
>> allow me to convert those names to the html version ("dami&aacute;n" and
>> "guzm&aacute;n") before display them ... any ideas will be most welcome
>> ... thanks
>
> Why not just declare your output encoding to match the encoding of the
> data in your database? Or better yet, convert the data in the database
> to UTF-8, which all modern browsers support and which Rails sets as
> default output encoding.
>
> HTML entities are handy for use in literals in your source code, but
> aren't really appropriate for your data in this case.


how can i convert the data in my database to utf8?
Michael G. (Guest)
on 2007-06-29 05:50
(Received via mailing list)
On Jun 25, 2007, at 9:22 , Damian Rr wrote:

> how can i convert the data in my database to utf8?

Depends on the database. For PostgreSQL you need to
* dump your database
* run the dump through iconv
* create a new database with the UTF8 encoding, and
* load your dumpfile into the new database.

Michael G.
grzm seespotcode net
This topic is locked and can not be replied to.