How do I use GBP pound sterling symbol in Ruby on Rail's number to currency method?
I am quite new to Ruby and Ruby on Rails.
While following a Ruby guide to create a small food finding application, the author used the number to currency method from Ruby on Rails. The trouble is the default unit is $
but I would l开发者_StackOverflow中文版ike to change it to £
.
When I did this in it gave me back the following error after I tried to run the code.
number_helper.rb:7 invalid multibyte char (US-ASCII) (SyntaxError)
Put the following in the first line of your file where you have £
.
#coding: utf-8
By default, ruby can read one-byte characters, which are US-ASCII characters. The £
character does not fit within US-ASCII code, and the magic comment above let ruby read the file as UTF-8 code, which is becoming standard, and is capable of handeling multi-byte characters, including £
(Added following the suggestion by the Tin Man).
Edit With Ruby 2.0 to be published this month, the default encoding will be UTF-8, so you will not need to do this anymore.
精彩评论