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


#1

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


#2

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


#3

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