这是使用after_save回调的正确方法吗?
class CouponsController < ApplicationController
after_save :remove_restrictions
private
def remove_restrictions
logger.debug("in after save")
end
end
此代码将错误抛出为
undefined method `after_save' for CouponsController:Class
使用after_save的正确方法是什么?
答案 0 :(得分:6)
应用程序/模型/ coupon.rb
class Coupon < ActiveRecord::Base
# after_save goes to your model
after_save :remove_restrictions
private
def remove_restrictions
logger.debug("in after save")
end
end
应用程序/控制器/ coupon_controller.rb
class CouponController < ApplicationController
# after_filters goes to your controller
after_filter :remove_restrictions
private
def remove_restrictions
logger.debug("in after filters")
end
end