1

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

1 Answer 1

5

Solved with proc

validates :amount, presence: true, inclusion: {in: proc {ApplicationSetting.current.card_amounts} }, on: :create
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.