Wednesday, March 9, 2011

Re: [Rails] validation order firing

On 9 March 2011 02:28, Jim Ruther Nill <jvnill@gmail.com> wrote:
> On Wed, Mar 9, 2011 at 10:19 AM, Me <chabgood@gmail.com> 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 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 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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate