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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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, 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.
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.