【发布时间】:2014-12-29 02:59:44
【问题描述】:
我有以下型号。
class Ingredient < ActiveRecord::Base
UNITS = [
{ name: "Unit" },
{ name: "Teaspoon" }
]
validates :unit, inclusion: UNITS.map{|u| I18n.t(u[:name]) }
end
在控制台中。在语言环境 if :fr (法语)时运行以下命令,会根据我的语言环境文件产生以下内容。
#Ingredient::UNITS.map{ |u| I18n.t(u[:name]) }
["Unité","Cuillère à café",]
这是正确的,但是当我执行以下操作时,验证失败。
Ingredient.create(quantity: 4.0, unit: "Cuillère à café")
当我手动检查该单元是否包含在数组中时,我得到了正确的结果。为什么此验证失败?适用于英语。
【问题讨论】:
标签: ruby-on-rails ruby validation activerecord internationalization