How can I use the pound sterling pound symbol in Ruby on Rail for the currency method?

I am new to Ruby and Ruby on Rails.

Following the Ruby tutorial to create a small product search application, the author used the currency method number from Ruby on Rails. The problem is that the default device is $ , but I would like to change it to Β£ .

When I did this, he gave me the following error after I tried to run the code.

 number_helper.rb:7 invalid multibyte char (US-ASCII) (SyntaxError) 
+6
source share
1 answer

Put the following on the first line of your file, where you have Β£ .

 #coding: utf-8 

By default, ruby ​​can read single-byte characters that are US-ASCII characters . The Β£ character does not fit into the US-ASCII code, and the magic comment above allows the ruby ​​to read the file as UTF-8 code, which becomes standard and is capable of handling multi-byte characters, including Β£ (Added after the Tin Man sentence).

Edit With Ruby 2.0, which will be published this month, the default encoding will be UTF-8, so you no longer need to do this.

+18
source

Source: https://habr.com/ru/post/886582/


All Articles