2017-04-21 62 views
0

Rails指南提供的I18n示波器特定於在ActiveRecord對象內使用ActiveModel::Validations。例如:如何在ActiveRecord之外使用ActiveModel :: Validation的I18N轉換?

en: 
    activerecord: 
    errors: 
     models: 
     some_model: 
      attributes: 
      name: 
       blank: "Please enter your full legal name." 

這不會以這種方式使用ActiveModel::Validations工作時:

class SomeModel 
    include ActiveModel::Validations 
    validates :name, presence: true 
end 

取而代之的是框架默認的「不能爲空」用於

豈今解決?

回答

1

activemodel代替activerecord修復此問題並允許所有後續範圍工作。示例:

en: 
    activemodel: # <--- 
    errors: 
     models: 
     message: 
      attributes: 
      name: 
       blank: "Please enter your name." 
相關問題