IN NEED OF EXPLANATION: class Comment < ActiveRecord::Base validate :must_be_friends def must_be_friends errors.add_to_base("Must be friends to leave a comment") unless commenter.friend_of?(commentee) end end The above code comes from rails documentation. There is a similar example inAgile Web Development with Rails by Dave Thomas and Sam Ruby. my understanding is that: validate :must_be_friends is a method call to the validate method within the ActiveRecord::Base class. Supposedly it''s contents are: def validate end This of course does not work with ruby because the validate method does not take parameters. Is metaporgramming being used? Tnis seems like some sort of Rails idiom. Please explain. I''m trying to get back into Rails after my first attempt. TIA, Pete -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
It''s a stub of sorts. When you use "validate :some_symbol" in your model, it''s basically adding that symbol to a stack that it''s going to invoke "model_instance.send(:some_symbol)" (more or less) on when validation happens. On Jan 22, 10:28 am, Hiro Protagonist <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> IN NEED OF EXPLANATION: > > class Comment < ActiveRecord::Base > validate :must_be_friends > > def must_be_friends > errors.add_to_base("Must be friends to leave a comment") > unless commenter.friend_of?(commentee) > end > end > > The above code comes from rails documentation. There is a similar > example inAgile Web Development with Rails by Dave Thomas and Sam Ruby. > > my understanding is that: > validate :must_be_friends > is a method call to the validate method within the ActiveRecord::Base > class. Supposedly it''s contents are: > def validate > end > > This of course does not work with ruby because the validate method does > not take parameters. > > Is metaporgramming being used? Tnis seems like some sort of Rails > idiom. > > Please explain. > > I''m trying to get back into Rails after my first attempt. > > TIA, > Pete > -- > Posted viahttp://www.ruby-forum.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.
On Jan 22, 3:28 pm, Hiro Protagonist <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> This of course does not work with ruby because the validate method does > not take parameters. > > Is metaporgramming being used? Tnis seems like some sort of Rails > idiom.Not really: there are two validate methods. One is an instance method that takes no arguments, the other is a class method that takes a method name or block and adds it to the list of validations to run (this is slightly hidden by the fact that that method comes from the ActiveSupport callback stuff) Fred> > Please explain. > > I''m trying to get back into Rails after my first attempt. > > TIA, > Pete > -- > Posted viahttp://www.ruby-forum.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.