Roman
(Roman)
April 11, 2013, 1:59pm
1
Hi,
What do you think about the following way to specify validations?
validates name: {presence: true}, email: {uniqueness: true, presence: true}
or even
validates name: [:presence], email: [:uniqueness, :presence]
Right now this requires 2 calls to validates
validates :user, presence: true
validates :email, uniqueness: true, presence: true
I think they are more confusing that the two calls
Hi,
The second version doesn’t allow to pass arguments to the validation type.
You can use this syntax :
with_options presence: true do |opts|
opts.validates :name
opts.validates :email, uniqueness: true
end
Best regards.
Roman
(Roman)
April 11, 2013, 2:10pm
4
@Rafael Imo, this syntax resembles how arguments for ActiveRecord.joins are specified.
@Geoffrey I just didn’t provide an example, but it does allow:
validates name: [:presence, format: {with: /\s+/}]
I don’t like that join syntax either.
This would only be good
for simple validation requirements. If there were an :if or :unless parameter on a given validation,
for example, that would look kind of ugly in the one line
version.
Wes
Roman
(Roman)
April 11, 2013, 6:20pm
7
Sure. It’s possible to make it ugly with the existing syntax as well This change would just add one more option, not disable all the existing ones.