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
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
I think they are more confusing that the two calls Rafael Mendonça França http://twitter.com/rafaelfranca https://github.com/rafaelfranca On Thu, Apr 11, 2013 at 10:59 AM, Roman <broilerster@gmail.com> wrote:> 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 > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-core+unsubscribe@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
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.
-----
Geoffrey Roguelon
Le 11 avr. 2013 à 15:59, Roman <broilerster@gmail.com> a écrit :
> 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
>
>
> --
> You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to rubyonrails-core+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
@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+/}]
On Thursday, April 11, 2013 5:04:14 PM UTC+3, Geoffrey Roguelon
wrote:>
> 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.
>
> -----
> Geoffrey Roguelon
>
> Le 11 avr. 2013 à 15:59, Roman <broil...@gmail.com
<javascript:>> a écrit
> :
>
> 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
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-co...@googlegroups.com <javascript:>.
> To post to this group, send email to
rubyonra...@googlegroups.com<javascript:>
> .
> Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
I don''t like that join syntax either. ;) Rafael Mendonça França http://twitter.com/rafaelfranca https://github.com/rafaelfranca On Thu, Apr 11, 2013 at 11:10 AM, Roman <broilerster@gmail.com> wrote:> @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+/}] > > > On Thursday, April 11, 2013 5:04:14 PM UTC+3, Geoffrey Roguelon wrote: > >> 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. >> >> ----- >> Geoffrey Roguelon >> >> Le 11 avr. 2013 à 15:59, Roman <broil...@gmail.com> a écrit : >> >> 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 >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Core" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rubyonrails-co...@**googlegroups.com. >> To post to this group, send email to rubyonra...@googlegroups.**com. >> >> Visit this group at http://groups.google.com/** >> group/rubyonrails-core?hl=en<http://groups.google.com/group/rubyonrails-core?hl=en> >> . >> For more options, visit https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> >> . >> >> >> >> >> -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-core+unsubscribe@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
This would only be good for simple validation requirements. If there were an :if or :unless parameteron a given validation, for example, that would look kind of ugly in the one line version. Wes On 4/11/13 8:59 AM, Roman wrote:> 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 > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send > an email to rubyonrails-core+unsubscribe@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
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. Best Regards, Roman 2013/4/11 Wes Gamble <weyus@att.net>> 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 > > On 4/11/13 8:59 AM, Roman wrote: > > 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 > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-core+unsubscribe@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Ruby on Rails: Core" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/rubyonrails-core/LETEqygulLQ/unsubscribe?hl=en > . > To unsubscribe from this group and all its topics, send an email to > rubyonrails-core+unsubscribe@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. For more options, visit https://groups.google.com/groups/opt_out.