On Friday, November 2, 2012 4:22:38 PM UTC+1, Jeff Cohen wrote:
>
> Rails 3 brought a slow death to another area of wonderful DSL-ness: 
> validations.  Instead of this:
>
>    validates_presence_of :title
>
> we're now supposed to use the generic form:
>
>    validates :title, :presence => true
>

My main issue with "validates" is that it's easy to mix up with "validate" 
(http://apidock.com/rails/v3.2.8/ActiveModel/Validations/ClassMethods/validate).

If you accidentally do "validate :title, presence: true", it will 
effectively do nothing, and won't explode - it will call the "title" method 
and expect that method to add validation errors, and "presence: true" just 
becomes an ignored option.

Tests will catch this, of course, but it's still an easy mistake to make.

I'm not sure what would be a good solution, though. Maybe complaining about 
unknown options?

-- 
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/-/FPthIt0hGf0J.
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