如何在全局Rails中设置#encoding:utf-8 [英] How to set #encoding: utf-8 in Rails globally

查看:101
本文介绍了如何在全局Rails中设置#encoding:utf-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在每个控制器中使用,其中:通知消息不在拉丁文
我试图将它放在ApplicationController中,试图在application.html.erb的顶部添加< meta charset =utf-8> ,没有工作任何帮助?



编辑:
config.encoding =utf-8也设置在 application.rb



编辑:



/ p>

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

这里有一个错误

 :语法错误,意外的$ end,expecting'}'..._或_to root_url,:notice => 'b $усусусусусусусусусусус}}}}}}} of of of of>>>>>>>>>>>>>>>>>> of>>>>>>>>>>>>>>>>>>>>>> 设置Ruby的全局默认编码1.9 ,但在您的情况下我建议使用 I18n 

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

#config / locales / ru.yml
ru:
会话:
destroy:
成功:对于本地密钥命名,AFAIK没有约定,这里我使用controller_name.action_name。结果方案。


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 ?

EDIT: config.encoding = "utf-8" also set in 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:

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.

这篇关于如何在全局Rails中设置#encoding:utf-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆