简体   繁体   中英

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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