Furkan Ayhan
Furkan Ayhan

Reputation: 1379

Why is the default encoding in Rails not UTF-8?

When I use UTF-8 characters (most of the time Turkish characters) in controllers, I have to add #encoding: utf-8 on the top of each controller file. Why doesn't Rails use this as a default?

edit: I have learnt that it is not about Rails, it is about Ruby.

Upvotes: 3

Views: 3460

Answers (2)

Jörg W Mittag
Jörg W Mittag

Reputation: 369438

Rails is not a programming language. It is just library written in Ruby. It cannot change the fundamental syntax of Ruby. Ruby 1.8 doesn't know anything about encodings, in Ruby 1.9 the default is ASCII and in Ruby 2.0 the default is UTF-8. There's nothing Rails can do about it.

Upvotes: 1

vgoff
vgoff

Reputation: 11313

Ruby 2.0 is UTF8 by default. Otherwise you must signify that in 1.9. According to naruse:

The default script encoding change.

Default script encoding (when magic comment is not specified) is changed into UTF8[#6679] In Ruby 1.9, the default script encoding is US-ASCII. We changed it to be UTF-8 after considering the following pros and cons. UTF-8 default is convenient because the majority of modern application uses UTF-8 This change doe not impact any 1.9 codes if Magic Comments are in place. The default script encoding in 1.9 without Magic Comment is either US-ASCII or ASCII-8BIT. In UTF-8, then some string manipulation could become slower.

Source: Rubyist Magazine

Upvotes: 6

Related Questions