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

ぃ、小莉子 提交于 2019-12-01 06:55:07

If you are using notepad++, first set the encoding to "Encode in UTF-8" and then start coding. If you have already created/saved the file then just changing the encoding type will not do. You will have to keep a copy of the existing code, then delete the existing file, open notepad++, set the encoding first(Encode in UTF-8) and then start writing/copying the code to it. This way utf-8 encoding is ensured and you won't have to put "# encoding: UTF-8" at the top of your file.

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

# encoding: utf-8

and on the first line of your .erb

<%# encoding: utf-8 %>

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

Hope this helps.

Make sure that in your database configurations utf-8 is the default character set, and not latin1.
If you use MySQL change it in the "MySQL Server Instance Config Wizard".

EDIT: Try putting this code in your application controller:

class ApplicationController < ActionController::Base
before_filter :set_charset

def set_charset
@headers["Content-Type"] = "text/html; charset=utf-8"
end
end

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

you can put

config.encoding = "utf-8"

in your config/application.rb which is equivalent to

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

which in turn is the equivalent to putting:

# encoding: UTF-8

or a BOM at the top of every file.

This allows utf-8 globally on all files of the rails app. If you want a global option on all ruby files, you can use the -Ku ruby option and set it via the RUBYOPT environment variable, like:

export RUBYOPT=-Ku 

This might be caused by the file encoding itself. Make sure you have set UTF-8 as default encoding for project in your editor/IDE preferences.

Edit:

You can check file for encoding with:

file -I myview.erb.html

(that's a capital 'i').

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!