On Wed, Mar 9, 2011 at 4:38 PM, Michael Pavling <[email protected]> wrote:

> On 9 March 2011 02:28, Jim Ruther Nill <[email protected]> wrote:
> > On Wed, Mar 9, 2011 at 10:19 AM, Me <[email protected]> wrote:
> >>
> >> If you have:
> >>
> >> validates_presence_of
> >> validates_uniqueness_of
> >> ...
> >>
> >> validates_each
> >>
> >>
> >> What fires in what order?
> >
> > the way you order them in your model file. so validates_presence_of goes
> > first,
> > uniqueness next then validates_each.
>
> Really? I'm not 100% sure that's right - although happy to be corrected.
>
> I've not looked at the source, but I was under the impression the
> validations were added to a hash that was iterated when "valid?" is
> called, and a hash returns its elements in no guaranteed order...
>
>
i'm not sure with rails 3, but i'm pretty sure with rails 2.x as i remember
adding comments in the models reminding coders to refrain from changing
the order of validations. since changing the validation orders changes the
order of the errors shown in the view.

but now that you mention it, maybe the order of when validations are run
is different with the order of errors shown.



> I tend to do stuff like:
>
>  validates_presence_of :foo
>  validates_uniqueness_of :foo, :if => :foo
>  validates_length_of :foo, :maximum => 255, :if => :foo
>
> --
> 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 [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>


-- 
-------------------------------------------------------------
visit my blog at http://jimlabs.heroku.com

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to