Multiple :on options?

Hey All,
Is it possible to have multiple entries for the :on option for the
‘validates’ validation?

Something like the following:
validates_format_of :some_user_attribute, :with => /
some_reg_ex/, :on => [:create, :update, :some_other_action]

Basically I would like to run one particular validation when multiple
actions are called in the controller. For example, I would like to
validate some user info on the ‘create’ action, on a ‘update’ action,
and possibly some other actions as well. I have found that I can do
it if I just copy the line above and have three separate ‘validates’
entries however it seems as though I’m just repeating myself.

Also, if there is a easier way of doing this, that’d be great too!

Thanks in advance!

On Oct 28, 10:44am, schmudu [email protected] wrote:

validate some user info on the ‘create’ action, on a ‘update’ action,
and possibly some other actions as well. I have found that I can do
it if I just copy the line above and have three separate ‘validates’
entries however it seems as though I’m just repeating myself.

There really isn’t anything to put in :some_other_action - the :on
attribute isn’t related to the controller action. From the docs:

:on - Specifies when this validation is active. Runs in all validation
contexts by default (nil), other options are :create and :update.

–Matt J.