2

I have discovered that all the files RoR generates when creating a new application seem to be saved with Western(ISO-8859-1) encoding (I am developing locally on a Windows machine). As a result I am having problems when using certain special characters eg £.

  • Should RoR be generating the framework files and saving them with Western(ISO-8859-1) encoding?
  • If not, how can I get RoR to generate the files and save them with UTF-8 encoding, and so avoid problems with certain characters eg £?

Please see Ruby on Rails - £ sign troubles for a previous unresolved question I asked relating to this problem.

Community
  • 1
  • 1
freshest
  • 6,229
  • 9
  • 35
  • 38

1 Answers1

1

Rails only uses ASCII characters in generated files.

ASCII files are neither UTF-8 nor ISO-8859-1. ASCII is compatible with both encodings, but an ASCII file doesn't become an ISO-8859-1 or UTF-8 file until you add a special character to it.

When you save a file after adding a £ character, you should make sure to set up your editor or IDE to use UTF-8 instead of ISO-8859-1. You should look for a configuration option in your editor. Rails cannot do anything about it.

If you run Ruby 1.9, also remember to set a magic comment at the top of a file containing special characters (except in templates). In Ruby 1.8 and previous versions, this comment has no effect.

# encoding: utf-8

The exact same problem causes the symptoms you describe in your other question.

For some background, see this (old but excellent) article about character encodings and Unicode.

molf
  • 73,644
  • 13
  • 135
  • 118
  • But why are the RoR framework files being generated and saved with ISO-8859-1 encoding? I thought the default encoding in RoR was UTF-8. – freshest Nov 11 '10 at 12:57
  • @freshest, RoR **doesn't** save files as ISO-8859-1, it saves them as ASCII. ASCII is compatible with both UTF-8 and ISO-8859-1. If you add a special character to an ASCII file, **that** is the moment you should specify the correct encoding. Rails doesn't add special characters to the files it generates. Therefore it is your editor configuration that is causing problems, not Rails. – molf Nov 11 '10 at 13:22
  • And also, the encoding the files are saved with is separate to the encoding that the generated HTML is sent with. Make sure that's correct too – Gareth Nov 11 '10 at 16:56