Is there a generally accepted way of overriding error (validation) messages from a gem/plugin in rails?
For example, I'm using the ActiveMerchant gem, and if someone puts in an American Express credit card number, but selects 'MasterCard', I get a not-very-descriptive "Type is not the correct card type" error.
I can easily get around this by doing something like this:
def validate_card
unless credit_card.valid?
credit_card.errors.full_messages.each do |message|
if message =~ /is not the correct card type/i
errors.add_to_base "This credit card number is invalid.
Please ensure that you selected the correct type."
else
errors.add_to_base message
end
end
end
end
but this technique quickly becomes unmaintainable and is clearly (at least in my opinion) far from 'best-practices'.
Similarly, I could unpack the ActiveMerchant gem and hack it up to put in my own custom error messages, but that also seems unmaintainable as it would require the same hacks to added into future, unpacked, versions of ActiveMerchant.