【发布时间】:2015-02-22 12:20:20
【问题描述】:
有时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
/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
/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
迁移20141231115801_create_specification_types.rb
每当我尝试调用@category.specification_types 时(查看或控制台) 我得到了例外:
I18n::InvalidLocale: :en is not a valid locale
轨道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'
....
我不明白 I18n 在哪里
我在项目中使用 I18n,但这里没有。 有 2 个语言环境,但我根本不使用 :en 语言环境。
请帮帮我。
【问题讨论】:
标签: ruby-on-rails exception rails-activerecord rails-i18n