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