I have:
AMOUNT = { '$ 0.50' => 0.5, '$ 1' => 1, '$ 2' => 2, '$ 5' => 5, '$ 10' => 10 }
Isn’t:
validates :amount, :inclusion => { :in => %w(0.5 1 2 5 10), :message => '%{value} is not a valid amount' }
the same thing as:
validates :amount, :inclusion => { :in => AMOUNT.values, :message => '%{value} is not a valid amount' }
With the former, everything works. With the latter, every time I submit, I get the validation message…
In the first one:
your
:inis an array of Strings. In your second one:your
:inis an array of Floats and Fixnums. Apparently youramountis a String during validation and10 != '10'is true.Try changing the values in your
AMOUNTto Strings or do the conversion when you build:in: