# Changing encoding on text

**URL:** <https://www.ruby-forum.com/t/changing-encoding-on-text/51248>\
**Category:** Rails\
**Created:** [December 28, 2005, 7:25pm UTC](https://www.ruby-forum.com/t/changing-encoding-on-text/51248 "2005-12-28T19:25:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mamatux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mamatux](https://www.ruby-forum.com/u/mamatux)\
**Post date:** [December 28, 2005, 7:25pm UTC](https://www.ruby-forum.com/t/changing-encoding-on-text/51248/1 "2005-12-28T19:25:34Z")

</div>

Hello,

I have a set of templates creating some files for me. All data on my  
site is encoded using iso-8859-1. Now I want to save the text in the  
file using utf-8. I have tried using iconv, but whenever I have the  
require “iconv” statement in my model, there is some error happening in  
the model and the model doesn’t get loaded (not sure how to debug that).

What approches to change encoding is there besides iconv?

Greetings,  
Gitte W.

---

<div class="post-metadata">

**Author:** ![mamatux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mamatux](https://www.ruby-forum.com/u/mamatux)\
**Post date:** [December 28, 2005, 8:40pm UTC](https://www.ruby-forum.com/t/changing-encoding-on-text/51248/2 "2005-12-28T20:40:59Z")

</div>

On 12/28/05, Gitte W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hello,
> 
> I have a set of templates creating some files for me. All data on my  
> site is encoded using iso-8859-1. Now I want to save the text in the  
> file using utf-8. I have tried using iconv, but whenever I have the  
> require “iconv” statement in my model, there is some error happening in  
> the model and the model doesn’t get loaded (not sure how to debug that).
> 
> What approches to change encoding is there besides iconv?

Try opening an irb session, and typing:  
require ‘iconv’  
Iconv.new(‘UTF-8’, ‘iso-8859-1’).iconv(‘Test’)

If that fails, at least you know your problem isn’t Rails-specific.  
If you’re on Windows, your problem could easily be:  
[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/170478](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/170478)

---

<div class="post-metadata">

**Author:** ![mamatux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mamatux](https://www.ruby-forum.com/u/mamatux)\
**Post date:** [December 28, 2005, 9:59pm UTC](https://www.ruby-forum.com/t/changing-encoding-on-text/51248/3 "2005-12-28T21:59:30Z")

</div>

Wilson B. wrote:

> > What approches to change encoding is there besides iconv?
> 
> Try opening an irb session, and typing:  
> require ‘iconv’  
> Iconv.new(‘UTF-8’, ‘iso-8859-1’).iconv(‘Test’)
> 
> If that fails, at least you know your problem isn’t Rails-specific.  
> If you’re on Windows, your problem could easily be:  
> [http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/170478](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/170478)

irb(main):001:0\> require “iconv”  
=\> true  
irb(main):002:0\> Iconv.new(‘UTF-8’, ‘iso-8859-1’).iconv(‘Test’)  
=\> “Test”

So - the iconv module works.  
I’m running it on freebsd so no windows issues here 🙂

I’m really not sure where it goes wrong …

Greetings,  
Gitte W.

---

<div class="post-metadata">

**Author:** ![mamatux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mamatux](https://www.ruby-forum.com/u/mamatux)\
**Post date:** [December 28, 2005, 10:44pm UTC](https://www.ruby-forum.com/t/changing-encoding-on-text/51248/4 "2005-12-28T22:44:59Z")

</div>

Wilson B. wrote:

> > > > site is encoded using iso-8859-1. Now I want to save the text in the
> > 
> > I’m running it on freebsd so no windows issues here 🙂
> > 
> > I’m really not sure where it goes wrong …

Sorry for the inconvinience - the problem has magically disappeared. (I  
suspect me testing code on one machine and testing the iconv stuff on  
another). Sorry!

Greetings,  
Gitte W.

---

<div class="post-metadata">

**Author:** ![mamatux](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mamatux](https://www.ruby-forum.com/u/mamatux)\
**Post date:** [December 28, 2005, 10:17pm UTC](https://www.ruby-forum.com/t/changing-encoding-on-text/51248/5 "2005-12-28T22:17:41Z")

</div>

On 12/28/05, Gitte W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > >
> 
> irb(main):001:0\> require “iconv”  
> =\> true  
> irb(main):002:0\> Iconv.new(‘UTF-8’, ‘iso-8859-1’).iconv(‘Test’)  
> =\> “Test”
> 
> So - the iconv module works.  
> I’m running it on freebsd so no windows issues here 🙂
> 
> I’m really not sure where it goes wrong …

Anything showing up in the development log?  
Can you create a test model that has the bare-minimum amount of code  
required to produce the problem? That might help isolate it.
