简体   繁体   中英

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 ..

用proc解决

validates :amount, presence: true, inclusion: {in: proc {ApplicationSetting.current.card_amounts} }, on: :create

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM