# How do I change character encoding from UTF-8 to ISO-8859-1?

**URL:** <https://www.ruby-forum.com/t/how-do-i-change-character-encoding-from-utf-8-to-iso-8859-1/106597>\
**Category:** Rails\
**Created:** [June 12, 2007, 10:14am UTC](https://www.ruby-forum.com/t/how-do-i-change-character-encoding-from-utf-8-to-iso-8859-1/106597 "2007-06-12T10:14:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hannes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f0a364/32.png) [@hannes](https://www.ruby-forum.com/u/hannes)\
**Post date:** [June 12, 2007, 10:14am UTC](https://www.ruby-forum.com/t/how-do-i-change-character-encoding-from-utf-8-to-iso-8859-1/106597/1 "2007-06-12T10:14:34Z")

</div>

Hi!

I have a Rails application that is using a MSSQL server/database. I need  
to change the character set encoding to ISO-8859-1. How do I do this???

I have added the defult\_cahrset to the environment.rb like:  
ActionController::Base.default\_charset=(‘ISO-8859-1’)

And I have set the attribute on the meta tag in the header like:

And also, since I am using the Aptana RadRails IDE I have set the  
text-file encoding property to ISO-8859-1.

But when I try to populate my database using the migration scripts I get  
an error saying:  
syntax error, unexpected tSTRING\_BEG  
unterminated string meets end of file

The line of code contains Swedish characters like Ã…, Ã„ and Ã–. If i  
remove the Ã–, all is fine. But this is not an option.

Need help fast!!!

Thanks!  
Hannes

---

<div class="post-metadata">

**Author:** ![hannes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f0a364/32.png) [@hannes](https://www.ruby-forum.com/u/hannes)\
**Post date:** [June 12, 2007, 10:56am UTC](https://www.ruby-forum.com/t/how-do-i-change-character-encoding-from-utf-8-to-iso-8859-1/106597/2 "2007-06-12T10:56:12Z")

</div>

On Jun 12, 2007, at 10:14 AM, Hannes Larsson wrote:

> The line of code contains Swedish characters like Å, Ä and Ö. If i  
> remove the Ö, all is fine. But this is not an option.

Rails sets $KCODE to “UTF8” by default since 1.2.

Thus, unless you set $KCODE to something else the Ruby interpreter  
expects source code in UTF-8. That is, your editor is using latin1 to  
write the file just fine, but Ruby still expects UTF-8 because you  
configure that option in the interpreter via $KCODE. Just assign

$KCODE = ‘NONE’

in environment.rb.

Additionally, it would be healthy to explicitely configure the  
database driver as well in database.yml, in MySQL that would be for  
example

encoding: latin1

– fxn

---

<div class="post-metadata">

**Author:** ![hannes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/f0a364/32.png) [@hannes](https://www.ruby-forum.com/u/hannes)\
**Post date:** [June 12, 2007, 12:30pm UTC](https://www.ruby-forum.com/t/how-do-i-change-character-encoding-from-utf-8-to-iso-8859-1/106597/3 "2007-06-12T12:30:31Z")

</div>

Xavier N. wrote:

> On Jun 12, 2007, at 10:14 AM, Hannes Larsson wrote:
> 
> > The line of code contains Swedish characters like ï¿½, ï¿½ and ï¿½. If i  
> > remove the ï¿½, all is fine. But this is not an option.
> 
> Rails sets $KCODE to “UTF8” by default since 1.2.
> 
> Thus, unless you set $KCODE to something else the Ruby interpreter  
> expects source code in UTF-8. That is, your editor is using latin1 to  
> write the file just fine, but Ruby still expects UTF-8 because you  
> configure that option in the interpreter via $KCODE. Just assign
> 
> $KCODE = ‘NONE’
> 
> in environment.rb.
> 
> Additionally, it would be healthy to explicitely configure the  
> database driver as well in database.yml, in MySQL that would be for  
> example
> 
> encoding: latin1
> 
> – fxn

Thanx a million!

added $KCODE = ‘NONE’ to environment.rb, now it all works as it suppose  
to! super and thanx again!

/Hannes
