# Problem saving data in different languages

**URL:** <https://www.ruby-forum.com/t/problem-saving-data-in-different-languages/79359>\
**Category:** Rails\
**Created:** [March 10, 2006, 5:34am UTC](https://www.ruby-forum.com/t/problem-saving-data-in-different-languages/79359 "2006-03-10T05:34:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 10, 2006, 5:34am UTC](https://www.ruby-forum.com/t/problem-saving-data-in-different-languages/79359/1 "2006-03-10T05:34:08Z")

</div>

Hi, I currently have a site that lets people enter info and submit it to  
the database. But the problem is the it lets people enter data in their  
language (portuguese and spanish) and all the special characters for  
those languages get replaced by symbols. Any idea how would I fix that?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 10, 2006, 6:44am UTC](https://www.ruby-forum.com/t/problem-saving-data-in-different-languages/79359/2 "2006-03-10T06:44:12Z")

</div>

This is kinda urgent, please.

Hi, I currently have a site that lets people enter info and submit it to  
the database. But the problem is the it lets people enter data in their  
language (portuguese and spanish) and all the special characters for  
those languages get replaced by symbols. Any idea how would I fix that?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 10, 2006, 7:22am UTC](https://www.ruby-forum.com/t/problem-saving-data-in-different-languages/79359/3 "2006-03-10T07:22:10Z")

</div>

2006/3/9, John [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi, I currently have a site that lets people enter info and submit it to  
> the database. But the problem is the it lets people enter data in their  
> language (portuguese and spanish) and all the special characters for  
> those languages get replaced by symbols. Any idea how would I fix that?

That partially depends on your database backend and some other things.  
Please see the How To Use Unicode Strings on the Rails Wiki:

[http://wiki.rubyonrails.org/rails/pages/HowToUseUnicodeStrings](http://wiki.rubyonrails.org/rails/pages/HowToUseUnicodeStrings)

In my case, I use Windows and only have the bit in config/database.yml  
and a before\_filter set in ApplicationController that sets my  
Content-Type to “application/xhtml+xml; charset=UTF-8”. Works fine  
for me. YMMV. My physical view files are also UTF-8 encoded. Rails  
simply copies bucket-o-bits around, and feels fine with it.

Bye !

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 10, 2006, 7:47am UTC](https://www.ruby-forum.com/t/problem-saving-data-in-different-languages/79359/4 "2006-03-10T07:47:02Z")

</div>

Thanks a lot, that worked.

FranÃ§ois Beausoleil wrote:

> 2006/3/9, John [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Hi, I currently have a site that lets people enter info and submit it to  
> > the database. But the problem is the it lets people enter data in their  
> > language (portuguese and spanish) and all the special characters for  
> > those languages get replaced by symbols. Any idea how would I fix that?
> 
> That partially depends on your database backend and some other things.  
> Please see the How To Use Unicode Strings on the Rails Wiki:
> 
> [http://wiki.rubyonrails.org/rails/pages/HowToUseUnicodeStrings](http://wiki.rubyonrails.org/rails/pages/HowToUseUnicodeStrings)
> 
> In my case, I use Windows and only have the bit in config/database.yml  
> and a before\_filter set in ApplicationController that sets my  
> Content-Type to “application/xhtml+xml; charset=UTF-8”. Works fine  
> for me. YMMV. My physical view files are also UTF-8 encoded. Rails  
> simply copies bucket-o-bits around, and feels fine with it.
> 
> Bye !

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 10, 2006, 7:40am UTC](https://www.ruby-forum.com/t/problem-saving-data-in-different-languages/79359/5 "2006-03-10T07:40:19Z")

</div>

A newbie question: I have configured the action mailed properly with  
correct smtp server, domain, login, password and port. Yet I cannot the  
system cannot sendout the emails, is there a log setting that I can  
enable to see the failure logs for ActionMailer? I do see in the  
development.log file that a template email that was suppose to be sent  
out was printed with working link to confirm the account creation. But  
no actual email gets sent out…

I have been trying to get this to work for a while with no luck.

Anu

----- Original Message ----  
From: Francois B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: removed\_email\_address@domain.invalid  
Sent: Thursday, March 9, 2006 10:20:25 PM  
Subject: Re: [Rails] Problem saving data in different languages

2006/3/9, John [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi, I currently have a site that lets people enter info and submit it to  
> the database. But the problem is the it lets people enter data in their  
> language (portuguese and spanish) and all the special characters for  
> those languages get replaced by symbols. Any idea how would I fix that?

That partially depends on your database backend and some other things.  
Please see the How To Use Unicode Strings on the Rails Wiki:

[http://wiki.rubyonrails.org/rails/pages/HowToUseUnicodeStrings](http://wiki.rubyonrails.org/rails/pages/HowToUseUnicodeStrings)

In my case, I use Windows and only have the bit in config/database.yml  
and a before\_filter set in ApplicationController that sets my  
Content-Type to “application/xhtml+xml; charset=UTF-8”. Works fine  
for me. YMMV. My physical view files are also UTF-8 encoded. Rails  
simply copies bucket-o-bits around, and feels fine with it.

## Bye !

FranÃ§ois Beausoleil  
[http://blog.teksol.info/](http://blog.teksol.info/)

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 10, 2006, 1:35pm UTC](https://www.ruby-forum.com/t/problem-saving-data-in-different-languages/79359/6 "2006-03-10T13:35:13Z")

</div>

Use UTF-8 for everything.

I’m a ruby-newbie myself, so the details are still fuzzy. Perhaps JRuby  
is mature enough to try?

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 10, 2006, 9:38pm UTC](https://www.ruby-forum.com/t/problem-saving-data-in-different-languages/79359/7 "2006-03-10T21:38:08Z")

</div>

John wrote:

> This is kinda urgent, please.
> 
> Hi, I currently have a site that lets people enter info and submit it to  
> the database. But the problem is the it lets people enter data in their  
> language (portuguese and spanish) and all the special characters for  
> those languages get replaced by symbols. Any idea how would I fix that?

There’s nothing broken, necessarily. Just make sure that whatever’s  
reading the data out of the database speaks the same character set as  
the data you’ve got in there, and all should be well, provided that  
everything’s in the _same_ character set.

To make sure that your information chain is all using the same character  
set, you need to:

- Set your http headers to the right charset on both standard actions  
and AJAX responses
- Set the character set in the META head tag.

If you’ve got a running app that’s got to remain collecting live info,  
don’t change anything yet until you understand what can be affected by  
your changes. The absolute last thing you want is a database with more  
than one character set in it.

---

<div class="post-metadata">

**Author:** ![john\_old](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@john\_old](https://www.ruby-forum.com/u/john_old)\
**Post date:** [March 30, 2006, 7:00am UTC](https://www.ruby-forum.com/t/problem-saving-data-in-different-languages/79359/8 "2006-03-30T07:00:52Z")

</div>

It works great on my database, as I can save all the spanish characters  
like Ã¡Ã©Ã­Ã³ÃºÃ¼Ã±, but when I write static text on rhtml pages themseves, I  
renders a question mark symbol on the static but the stuff from the  
database looks fine. I’ve added a few things, including code like…

\< meta http-equiv=“content-type” content=“text/html; charset=utf-8” / \>

…and…

class ApplicationController \< ActionController::Base  
before\_filter :set\_charset

def set\_charset  
@headers[“Content-Type”] = “text/html; charset=utf-8”  
suppress(ActiveRecord::StatementInvalid) do  
ActiveRecord::Base.connection.execute ‘SET NAMES UTF8’  
end  
end  
end

…and…

encoding: utf-8

…on datbase.yml. Some of these did fix the database problems, at  
least!
