Rails 1.2 RC1 problem

Hi

Have this helper method inside a sites_helper.rb module

def distritos [ [‘0’, ‘Todos’], [‘1’, ‘Aveiro’], [‘2’, ‘Beja’], [‘3’, ‘Braga’], [‘4’, ‘Brangança’],

  ['5', 'Castelo Branco'],
  ['6', 'Coimbra'],
  ['7', 'Évora'],
  ['8', 'Faro'],
  ['9', 'Guarda'],
  ['10', 'Leiria'],
  ['11', 'Lisboa'],
  ['12', 'Portalegre'],

  ['13', 'Porto'],
  ['14', 'Santarém'],
  ['15', 'Setúbal'],
  ['16', 'Viana do Castelo'],
  ['17', 'Vila Real'],
  ['18', 'Viseu']
]

end

this is used to polulate some lists on a view, but i get the following errors. It works fine with rails 1.1.2

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:9: parse error, unexpected tINTEGER, expecting ‘]’ [‘5’, ‘Castelo Branco’], ^ /var/rails/LocaisVoo/app/helpers/sites_helper.rb:9: parse error, unexpected tCONSTANT, expecting kEND

  ['5', 'Castelo Branco'],
                ^

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:10: parse error, unexpected tINTEGER, expecting kEND [‘6’, ‘Coimbra’], ^ /var/rails/LocaisVoo/app/helpers/sites_helper.rb:10: parse error, unexpected tCONSTANT, expecting kEND

  ['6', 'Coimbra'],
                ^

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:11: parse error, unexpected tINTEGER, expecting kEND [‘7’, ‘�vora’], ^ /var/rails/LocaisVoo/app/helpers/sites_helper.rb:11: parse error, unexpected tIDENTIFIER, expecting kEND

  ['7', '�vora'],
              ^

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:12: parse error, unexpected tINTEGER, expecting kEND [‘8’, ‘Faro’], ^ /var/rails/LocaisVoo/app/helpers/sites_helper.rb:12: parse error, unexpected tCONSTANT, expecting kEND

  ['8', 'Faro'],
             ^

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:13: parse error, unexpected tINTEGER, expecting kEND [‘9’, ‘Guarda’], ^ /var/rails/LocaisVoo/app/helpers/sites_helper.rb:13: parse error, unexpected tCONSTANT, expecting kEND

  ['9', 'Guarda'],
               ^

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:14: parse error, unexpected tINTEGER, expecting kEND [‘10’, ‘Leiria’], ^ /var/rails/LocaisVoo/app/helpers/sites_helper.rb:14: parse error, unexpected tCONSTANT, expecting kEND

  ['10', 'Leiria'],
                ^

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:15: parse error, unexpected tINTEGER, expecting kEND [‘11’, ‘Lisboa’], ^ /var/rails/LocaisVoo/app/helpers/sites_helper.rb:15: parse error, unexpected tCONSTANT, expecting kEND

  ['11', 'Lisboa'],
                ^

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:16: parse error, unexpected tINTEGER, expecting kEND [‘12’, ‘Portalegre’], ^ /var/rails/LocaisVoo/app/helpers/sites_helper.rb:16: parse error, unexpected tCONSTANT, expecting kEND

  ['12', 'Portalegre'],
                    ^

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:17: parse error, unexpected tINTEGER, expecting kEND [‘13’, ‘Porto’], ^ /var/rails/LocaisVoo/app/helpers/sites_helper.rb:17: parse error, unexpected tCONSTANT, expecting kEND

  ['13', 'Porto'],
               ^

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:18: parse error, unexpected tINTEGER, expecting kEND [‘14’, ‘Santar�m’], ^ /var/rails/LocaisVoo/app/helpers/sites_helper.rb:18: parse error, unexpected tCONSTANT, expecting kEND

  ['14', 'Santar�m'],
                   ^

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:20: parse error, unexpected tINTEGER, expecting ‘]’ [‘16’, ‘Viana do Castelo’], ^ /var/rails/LocaisVoo/app/helpers/sites_helper.rb:20: parse error, unexpected tCONSTANT, expecting kEND

  ['16', 'Viana do Castelo'],
               ^

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:21: parse error, unexpected tINTEGER, expecting kEND [‘17’, ‘Vila Real’], ^ /var/rails/LocaisVoo/app/helpers/sites_helper.rb:21: parse error, unexpected tCONSTANT, expecting kEND

  ['17', 'Vila Real'],
              ^

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:22: parse error, unexpected tINTEGER, expecting kEND [‘18’, ‘Viseu’] ^ /var/rails/LocaisVoo/app/helpers/sites_helper.rb:22: parse error, unexpected tCONSTANT, expecting kEND

  ['18', 'Viseu']
               ^

/var/rails/LocaisVoo/app/helpers/sites_helper.rb:22: unterminated string meets end of file /var/rails/LocaisVoo/app/helpers/sites_helper.rb:22: parse error, unexpected $, expecting kEND

If I remove the characters with accents it works as expected.

Thanks in advance for any hint

This error happens just by having that method inside the file. It sounds like a parse problem.

I assume the file is utf-8? Have you set your Rails character set to
utf-8? In Rails 1.2 you need to add a:

  ActionController::Base.default_charset = 'utf-8'

to your environment.rb. I believe this will then set $KCODE for you
automatically.

Cheers,

Pete Yandell http://aliencamel.com/

I assume the file is utf-8? Have you set your Rails character set to utf-8? In Rails 1.2 you need to add a:

  ActionController::Base.default_charset = 'utf-8'

to your environment.rb. I believe this will then set $KCODE for you automatically.

Actually, that's the default in Rails 1.2. So it sounds like something else is the problem. Like whether the file itself is a UTF-8 file.

I assume the file is utf-8? Have you set your Rails character set to utf-8? In Rails 1.2 you need to add a:

  ActionController::Base.default_charset = 'utf-8'

to your environment.rb. I believe this will then set $KCODE for you automatically.

Actually, that's the default in Rails 1.2. So it sounds like something else is the problem. Like whether the file itself is a UTF-8 file.

Thanks David and Pete

You’re right. The file was not in UTF-8, it was in ISO-8859-1.

Have forced character encoding to UTF-8 and the pages are been parsed without errors, I have to change all files to utf-8 no problem about it.

BUT (always one)

All the data was saved to the BD in ISO-8859-1, so all the content is garbled. And thats really a problem, it will take a lot of time to correct everything.

Multibyte is the way to go but i cannot afford it at the moment.

I’ll be reverting to 1.1.6 for now.

Thanks.

DHH wrote:

Actually, that's the default in Rails 1.2. So it sounds like something else is the problem. Like whether the file itself is a UTF-8 file.

Open the source file with a hex editor and look for the BOM in the first 2 or 4 bytes.

Editors like Notepad like to add those things, and sometimes they screw up the reader, though they are technically well-formed. And sometimes they lie about the rest of the file.