Carlos,

I agree with you. Technically I can check that errors are empty, but I have 
to do it in all my custom validations.

it will not look nice :(

What I offer is a two stage validation. When on the second stage you will 
be sure that all data in correct state and you can use it with confidence.

Anyway you will rely on one *valid?* method.

What I added into my project is:

https://gist.github.com/2987785

The reason I did it is a lot of exceptions we got when our clients didn't 
provide all necessary data (or in correct format).
The obvious solution of course was to manually check all data in custom 
validations, but why I need to duplicate code if AR/AM already implemented 
it?

On Thursday, June 21, 2012 4:07:09 PM UTC+3, Carlos Antonio da Silva wrote:
>
> I agree with Steve, when we call valid?, we expect all validations to run. 
> If you want to skip some validation in case errors already exist in the 
> object for any particular reason, you can always to that as you said: `if 
> errors.empty?`. This will give you the behavior you expect, although I'd 
> recommend avoiding this and running all validations.
>
> -- 
> At.
> Carlos Antonio
>
> On Thursday, June 21, 2012 at 9:51 AM, Steve Klabnik wrote:
>
> I think I'd be much more annoyed by this kind of behavior. "Okay,
> these two things are wrong. Let's fix them. Wait, now it's _still_
> wrong, with something totally unrelated?"
>
> You could fix this case almost trivially by 'if age.to_i < 16', right?
> I mean, I know you're talking about a more general case, but...
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Core" 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-core?hl=en.
>
>  
>  

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-core/-/ZqmMH9fvXe0J.
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-core?hl=en.

Reply via email to