I'm using a custom validation to check if a card has expired (it has a month / year).
Here's what I've got:
validate :card_not_expired
def card_not_expired
if exp_year > Time.now.year or
(exp_year == Time.now.year and exp_month >= Time.now.month)
true
end
end
I'm getting a undefined method ">=" for nil:NilClass
message, presumably because the exp_month
and exp_year
fields can't be accessed directly in the Model. I tried using the symbol form (:exp_month
) but not surprisingly, that didn't work either.
How do I get it to work?