I am trying to implement before_destroy on a model. While I am following this before_destroy example I either receive a NameError or end up with something which doesn't do the before_destroy. What's wrong with my syntax?
class Person < ActiveRecord::Base
has_many :book_loans, :order => 'return_date desc'
has_many :books, :through => :book_loans
before_destroy
errors.add_to_base "Cannot delete borrower with loans" unless
book_loans.count == 0
end
Doesn't Compile
before_destroy
errors.add_to_base "Cannot delete borrower with loans" unless
book_loans.count == 0
Doesn't Work
def before_destroy
errors.add_to_base "Cannot delete borrower with loans" unless
book_loans.count == 0
end