Aje*_*jey 0 callback after-save ruby-on-rails-3
这是使用after_save回调的正确方法吗?
class CouponsController < ApplicationController
after_save :remove_restrictions
private
def remove_restrictions
logger.debug("in after save")
end
end
Run Code Online (Sandbox Code Playgroud)
此代码将错误抛出为
undefined method `after_save' for CouponsController:Class
Run Code Online (Sandbox Code Playgroud)
使用after_save的正确方法是什么?
应用程序/模型/ 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
Run Code Online (Sandbox Code Playgroud)
应用程序/控制器/ 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
Run Code Online (Sandbox Code Playgroud)