1

我正在使用活动的 activeAdmin 将我的源代码文件 yaml 翻译成葡萄牙语:

"pt-PT":
  activerecord:
    models:
      position:
        one: "Posição"
        other: "Posições"

痕迹:

Encoding::CompatibilityError in Admin::PositionsController#index

incompatible character encodings: ASCII-8BIT and UTF-8

activeadmin (0.4.4) lib/activeadmin/arbre/html/collection.rb:20:in join'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:intos'
activeadmin (0.4.4) lib/active_admin/arbre/html/element.rb:115:in content'
activeadmin (0.4.4) lib/active_admin/arbre/html/tag.rb:76:into_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:21:in block in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:incollect'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/element.rb:115:incontent'
activeadmin (0.4.4) lib/active_admin/arbre/html/tag.rb:76:in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:21:inblock in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:in collect'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:into_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/element.rb:115:in content'
activeadmin (0.4.4) lib/active_admin/arbre/html/tag.rb:76:into_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:21:in block in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:incollect'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/element.rb:115:incontent'
activeadmin (0.4.4) lib/active_admin/arbre/html/tag.rb:76:in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:21:inblock in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:in collect'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:into_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/element.rb:115:in content'
activeadmin (0.4.4) lib/active_admin/arbre/html/tag.rb:76:into_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:21:in block in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:incollect'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/element.rb:115:incontent'
activeadmin (0.4.4) lib/active_admin/arbre/html/tag.rb:76:in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:21:inblock in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:in collect'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:into_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/element.rb:115:in content'
activeadmin (0.4.4) lib/active_admin/arbre/html/tag.rb:76:into_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/document.rb:25:in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:21:inblock in to_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:in collect'
activeadmin (0.4.4) lib/active_admin/arbre/html/collection.rb:20:into_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/element.rb:115:in content'
activeadmin (0.4.4) lib/active_admin/arbre/html/element.rb:135:into_s'
activeadmin (0.4.4) lib/active_admin/arbre/html/element.rb:131:in to_str'
rack (1.4.1) lib/rack/etag.rb:56:injoin'
rack (1.4.1) lib/rack/etag.rb:56:in digest_body'
rack (1.4.1) lib/rack/etag.rb:26:incall'
rack (1.4.1) lib/rack/conditionalget.rb:25:in call'
actionpack (3.2.3) lib/action_dispatch/middleware/head.rb:14:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/params_parser.rb:21:in call'
actionpack (3.2.3) lib/action_dispatch/middleware/flash.rb:242:incall'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/cookies.rb:338:in call'
activerecord (3.2.3) lib/active_record/query_cache.rb:64:incall'
activerecord (3.2.3) lib/active_record/connection_adapters/abstract/connection_pool.rb:467:in call'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:28:inblock in call'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run765012194call948180406_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:405:in `_run_callback'
activesupport (3.2.3) lib/active_support/callbacks.rb:385:in _run_call_callbacks'
activesupport (3.2.3) lib/active_support/callbacks.rb:81:inrun_callbacks'
actionpack (3.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in call'
actionpack (3.2.3) lib/action_dispatch/middleware/reloader.rb:65:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/remote_ip.rb:31:in call'
actionpack (3.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:16:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/show_exceptions.rb:56:in call'
railties (3.2.3) lib/rails/rack/logger.rb:26:incall_app'
railties (3.2.3) lib/rails/rack/logger.rb:16:in call'
actionpack (3.2.3) lib/action_dispatch/middleware/request_id.rb:22:incall'
rack (1.4.1) lib/rack/methodoverride.rb:21:in call'
rack (1.4.1) lib/rack/runtime.rb:17:incall'
activesupport (3.2.3) lib/active_support/cache/strategy/local_cache.rb:72:in call'
rack (1.4.1) lib/rack/lock.rb:15:incall'
actionpack (3.2.3) lib/action_dispatch/middleware/static.rb:62:in call'
railties (3.2.3) lib/rails/engine.rb:479:incall'
railties (3.2.3) lib/rails/application.rb:220:in call'
rack (1.4.1) lib/rack/content_length.rb:14:incall'
railties (3.2.3) lib/rails/rack/log_tailer.rb:14:in call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:inservice'
/home/ruby/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in service'
/home/ruby/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:inrun'
/home/ruby/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

该错误是由于在数据库中的两个文件 yaml 中使用特殊字符引起的,有人可以帮我解决吗?

4

1 回答 1

1

你能检查你的编辑器是否以 UTF8 保存你的文件吗?

如果它仍然不起作用,请尝试在文件顶部添加这一行(你是正确的,它在 yml 文件中没有用,只是在 rb 文件中):# encoding: utf-8

编辑:更多配置

确保您有:

在您的 application.rb 中:

config.encoding = "utf-8"

在您的 config/environment.rb 中:

Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
于 2012-09-10T15:37:45.133 回答