Ruby on Rails Friday, October 28, 2011

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!

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment