gre*_*nif 4 ruby-on-rails exception rails-i18n rails-activerecord
有时 Rails 很漂亮,但有时却很糟糕。尤其是当你遇到奇怪的异常时
我有 3 个简单的模型
/app/models/specification_type.rb
class SpecificationType < ActiveRecord::Base#< AbstractModel
has_many :scpecification_type_to_category_relations, class_name: "Relations::SpecificationTypeToCategory"
has_many :categories, through: :scpecification_type_to_category_relations
end
Run Code Online (Sandbox Code Playgroud)
/app/models/category.rb
class Category < ActiveRecord::Base#AbstractModel
has_many :groups
has_many :products
has_many :scpecification_type_to_category_relations, class_name: "Relations::SpecificationTypeToCategory"
has_many :specification_types, through: :scpecification_type_to_category_relations
end
Run Code Online (Sandbox Code Playgroud)
/app/models/relations/specification_type_to_category.rb
class Relations::SpecificationTypeToCategory < ActiveRecord::Base
self.table_name = "specification_type_to_category_relations"
belongs_to :scpecification_type
belongs_to :category
end
Run Code Online (Sandbox Code Playgroud)
迁移20141231115801_create_specation_types.rb
每次在任何地方(视图或控制台),当我尝试调用 @category.specation_types 时,都会出现异常:
I18n::InvalidLocale: :en is not a valid locale
Run Code Online (Sandbox Code Playgroud)
导轨c
Category.first.specification_types
Category Load (0.3ms) SELECT `categories`.* FROM `categories` ORDER BY `categories`.`id` ASC LIMIT 1
I18n::InvalidLocale: :en is not a valid locale
from /home/anton/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n.rb:284:in `enforce_available_locales!'
from /home/anton/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/i18n-0.7.0/lib/i18n.rb:151:in `translate'
from /home/anton/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activesupport-4.2.0/lib/active_support/core_ext/array/conversions.rb:68:in `to_sentence'
from /home/anton/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/associations.rb:60:in `initialize'
from /home/anton/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/reflection.rb:840:in `new'
from /home/anton/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/reflection.rb:840:in `check_validity!'
from /home/anton/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/activerecord-4.2.0/lib/active_record/associations/association.rb:25:in `initialize'
....
Run Code Online (Sandbox Code Playgroud)
我不明白 I18n 在哪里
我在项目中使用了 I18n,但这里没有。有 2 个语言环境,但我根本不使用 :en locale。
请帮帮我。
这个错误是非常原始的。: 规范类型中的额外字母“c”。但要查看我在 application.rb 中设置的人类可读的异常
config.i18n.enforce_available_locales = false
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
952 次 |
| 最近记录: |