On Oct 28, 10:44 am, schmudu <patrick.robin....@gmail.com> wrote:
> 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.
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 Jones
--
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