I want to provide some help to my users for filling out forms. So let’s assume I have a model customer with
validates_presence_of :email
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :message => 'must be a valid email address'
Now I want to get the error messages that belong to :email without actually invoking them. So I need the string “(email) can’t be blank” and “(email) must be a valid email address” to print them out as tooltips on my registration forms.
So is there any way to obtain them?
Customer.validators will get you an array of validators, then you can iterate them and get, for example: Customer.validators[0].options[:message].