可选参数
class User < ActiveRecord::Base
before_validation :normalize_name, on: :create
# :on takes an array as well
after_validation :set_location, on: [ :create, :update ]
protected
def normalize_name
self.name = self.name.downcase.titleize
end
def set_location
self.location = LocationService.query(self)
end
endclass Topic < ActiveRecord::Base
has_many :children, dependent: destroy
before_destroy :log_children
private
def log_children
# Child processing
end
end最后更新于