Guys, there are people who see a value in validation dependency and who don't.
I want to add this to Rails core and ready to make a pull request. But I need some help about the name of the method (validate_after, validate_with_dependency, validate_further, etc.) and usage of this approach. I posted earlier what I use on my project. I think that the interface of this method should be the same with validate method (:on, :if/:unless). On Thursday, June 21, 2012 1:56:39 PM UTC+3, Pavel Gabriel wrote: > > Hi! > > I found that it's a popular use case for AR/AM validations: > > class User < AR::Base > validates_numericality_of :age > > #custom validation > validate :user_older_16 > > def user_older_16 > errors.add(:age, "should be older 16") if age <= 16 > end > end > > When you will try to validate as the following: > > user = User.new(age: 'bla') > user.valid? > > you will get: ArgumentError: comparison of String with 16 failed. > > Folks write a lot of code to check attribute values in their custom > validations, but it's not a DRY way because attributes already validated by > AM. > > Is it a good idea to run validation methods only if errors.count == 0? > > Or maybe we can add something like "validate_further :user_older_16" that > will run only if attributes are valid? > > -- 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/-/B96Dkulph2IJ. 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.
