I am finding it hard to do some validation with my custom made validator.
Here it is:
class SomeValidator < ActiveModel::Validator
def validate(record)
if record.baggage > options[:max]
record.errors[:baggage] << "is over #{options[:max]}."
end
end
end
Now I am trying to send it this number which needs to be read from another model. This is my validated model:
class Seat < ActiveRecord::Base
belongs_to :flight
validates :baggage, :some => {:max => flight.max_allowance}
end
Where flight is the other model, and max_allowance is the number I want to read. This doesn’t work of course.
Any suggestions?
You can use a Proc as argument. Something like this: