How to allow right to left languages ​​in Ruby on Rails 3

I am interested in building a website in Hebrew using Ruby on Rails 3. The problem is when I put Hebrew in my opinion. They tell me that it is not supported, and I have to add UTF-8.

I have been working on this for a while, and I cannot find how to do this. I also use Sqlite3, and I would also like to keep Hebrew strings.

How can i achieve this?

The error code I give is:

Your template was not saved as valid UTF-8. Please either specify UTF-8 as the encoding for your template in your text editor, or mark the template with its encoding by inserting the following as the first line of the template:...

Edit:

The problem was that I was working on Notepad ++, which did not save my files in UTF-8 format, although they were UTF-8-generated files. Solved by changing the file format.

+4
source share
5 answers

If you use notepad ++, first set the encoding to "Encode in UTF-8", and then run the encoding. If you have already created / saved the file, simply changing the encoding type will not work. You will need to save a copy of the existing code, then delete the existing file, open Notepad ++, first set the encoding (Encode in UTF-8), and then start writing / copying the code. This ensures utf-8 encoding, and you will not need to put "# encoding: UTF-8" at the beginning of the file.

+2
source

You should try adding the following to the first line of your .rb files:

 # encoding: utf-8 

and in the first line of your .erb

 <%# encoding: utf-8 %> 

encoding: utf-8 and coding: utf-8 equivalent.

Hope this helps.

+2
source

Make sure that in your database settings utf-8 is the default character set, not latin1.
If you are using MySQL, modify it in the "MySQL Server Instance Configuration Wizard".

EDIT: try putting this code in the application controller:

 class ApplicationController < ActionController::Base before_filter :set_charset def set_charset @headers["Content-Type"] = "text/html; charset=utf-8" end end 

more about this article: http://www.dotmana.com/?p=95

+2
source

you can put

 config.encoding = "utf-8" 

in config/application.rb which is equivalent

 Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 

which in turn is equivalent to:

 # encoding: UTF-8 

or specification at the top of each file.

This allows utf-8 to be used in all rails application files. If you want a global option for all ruby ​​files, you can use the -Ku ruby option and set it through the RUBYOPT environment RUBYOPT , for example:

 export RUBYOPT=-Ku 
+1
source

This may be caused by the encoding of the file itself. Make sure you configure UTF-8 as the default encoding for the project in your editor / IDE settings.

Edit:

You can check the file for encoding with:

 file -I myview.erb.html 

(that capital is "i").

0
source

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


All Articles