简体   繁体   English

如何在全局的Rails中设置#encoding:utf-8

[英]How to set #encoding: utf-8 in Rails globally

now i'm using # encoding: utf-8 in every controller, where :notice message is not in latin i've tried to put it in ApplicationController, tried to add <meta charset="utf-8"> at the top of application.html.erb, none worked, any help ? 现在我在每个控制器中使用# encoding: utf-8 ,其中:通知消息不在拉丁语中我试图将它放在ApplicationController中,试图在顶部添加<meta charset="utf-8"> application.html.erb,没有工作,有什么帮助吗?

EDIT: config.encoding = "utf-8" also set in application.rb 编辑: config.encoding =“utf-8”也在application.rb中设置

EDIT: 编辑:

error appears with this code: 此代码出现错误:

redirect_to root_url, :notice => "Вышли успешно"

and here's an error 这是一个错误

:syntax error, unexpected $end, expecting '}' ..._or_to root_url, :notice => 'Вышли успешно.' }

This is a duplicate of Set global default encoding for ruby 1.9 , but in your case I suggest using the I18n : 这是ruby 1.9Set global default encoding的副本,但在你的情况下,我建议使用I18n

redirect_to root_url, :notice => I18n.t 'sessions.destroy.success'

# config/locales/ru.yml
ru:
  sessions:
    destroy:
      success: Вышли успешно

As for locales key naming, AFAIK there's no convention, here I use "controller_name.action_name.result" scheme. 至于locales键命名,AFAIK没有约定,这里我使用“controller_name.action_name.result”方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM