[英]Rails validates inclusion with variable array
I'm trying to create a validator on an integer array but this array ca be modified and I think my validator inclusion array is not reload. 我正在尝试在整数数组上创建验证器,但是可以修改此数组,并且我认为我的验证器包含数组未重新加载。
This is my validator before 这是我之前的验证器
validates :amount, presence: true, inclusion: {in: [25, 50, 75, 100, 150, 200, 250]}, on: :create
But now admins can enable of disable an amount 但是现在管理员可以启用禁用金额
validates :amount, presence: true, inclusion: {in: ApplicationSetting.current.card_amounts }, on: :create
Any idea how in can 'reload' this inclusion array ? 知道如何才能“重新加载”此包含数组吗?
ps: If I raise in the code the array in reload .. ps:如果我在代码中引发reload中的数组。
用proc解决
validates :amount, presence: true, inclusion: {in: proc {ApplicationSetting.current.card_amounts} }, on: :create
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.