Hello, I am following the railstutorial.org. The model User that is being developed [1] is using an active record "validates" helper that I want to know more about. However, when I search [2] I can''t seem to find any reference to this helper. I was under the impression that "validates" is the new way (rails 3) while the helpers documented in [2] were the old method. Is this correct? Where can I read more about "validates"? Daniel [1] http://github.com/dlidstrom/bowling/blob/master/app/models/user.rb [2] http://guides.rubyonrails.org/active_record_validations_callbacks.html -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-16 11:34 UTC
Re: Documentation for active record "validates" helper
validates triggers when validation accurds but it does not perform validation by it sellf you have to pass it the validation function validates :to_many_drinks def to_many_drinks self.drinks > 80 errors.add(:drinks, "LOL") end this add errors to the drinks column with a "LOL" message On Wed, Sep 15, 2010 at 5:06 AM, Daniel Lidström <dlidstrom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Hello, > > I am following the railstutorial.org. The model User that is being > developed [1] is using an active record "validates" helper that I want > to know more about. However, when I search [2] I can''t seem to find > any reference to this helper. I was under the impression that > "validates" is the new way (rails 3) while the helpers documented in > [2] were the old method. Is this correct? Where can I read more about > "validates"? > > Daniel > > [1] http://github.com/dlidstrom/bowling/blob/master/app/models/user.rb > [2] http://guides.rubyonrails.org/active_record_validations_callbacks.html > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Daniel Lidström
2010-Sep-17 14:46 UTC
Re: Documentation for active record "validates" helper
On 16 Sep, 13:34, radhames brito <rbri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> validates triggers when validation accurds but it does not perform > validation by it sellf you have to pass it the validation function > > validates :to_many_drinks > > def to_many_drinks > self.drinks > 80 > errors.add(:drinks, "LOL") > end > > this add errors to the drinks column with a "LOL" messageI am not sure this is correct. This is what I am doing within my model: validates :name, :presence => true, :length => { :maximum => 50 } The above validates the name attribute, makes sure it is present and of maximu 50 characters. Both presence and length were provided by ActiveRecord (I belive), certainly not by me. But my real question is: where is this documented? Daniel -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Greg Donald
2010-Sep-17 14:49 UTC
Re: Re: Documentation for active record "validates" helper
On Fri, Sep 17, 2010 at 9:46 AM, Daniel Lidström <dlidstrom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> validates :name, :presence => true, > :length => { :maximum => 50 } > > The above validates the name attribute, makes sure it is present and > of maximu 50 characters. Both presence and length were provided by > ActiveRecord (I belive), certainly not by me. But my real question is: > where is this documented?http://www.railsapi.com/doc/rails-v3.0.0/classes/ActiveModel/Validations/ClassMethods.html#M003721 -- Greg Donald destiney.com | gregdonald.com -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-17 15:02 UTC
Re: Re: Documentation for active record "validates" helper
sorry the code i posted was for rails 2.3.x -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
radhames brito
2010-Sep-17 15:03 UTC
Re: Re: Documentation for active record "validates" helper
watch this http://railscasts.com/episodes/211-validations-in-rails-3 On Fri, Sep 17, 2010 at 11:02 AM, radhames brito <rbritom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> sorry the code i posted was for rails 2.3.x > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Daniel Lidström
2010-Sep-19 15:18 UTC
Re: Documentation for active record "validates" helper
> http://www.railsapi.com/doc/rails-v3.0.0/classes/ActiveModel/Validati... > > -- > Greg Donald > destiney.com | gregdonald.comThank you Greg! Daniel -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.