Ruby on rails 3 保存错误后的Rails

Ruby on rails 3 保存错误后的Rails,ruby-on-rails-3,callback,after-save,Ruby On Rails 3,Callback,After Save,这是使用after_save回调的正确方法吗 class CouponsController < ApplicationController after_save :remove_restrictions private def remove_restrictions logger.debug("in after save") end end 保存后使用的正确方法是什么?app/models/coupon.rb class Coupon < Act

这是使用after_save回调的正确方法吗

class CouponsController < ApplicationController
after_save :remove_restrictions
 private
    def remove_restrictions

      logger.debug("in after save")
    end

end
保存后使用的正确方法是什么?

app/models/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
class优惠券
应用程序/控制器/优惠券控制器.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
类耦合控制器
app/models/优惠券.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
class优惠券
应用程序/控制器/优惠券控制器.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
类耦合控制器
将保存后的内容放入Model@rubyist-如果你想把这个作为答案,我会删除我的。我想我们差不多在同一时间回答了。把你的“后保存”放在你的Model@rubyist-如果你想把这个作为答案,我会删除我的。我想我们差不多同时回答了。哎呀,我的错!现在明白了,Thxbtw,我很好奇我能在after_save回调中查询记录吗?我的意思是我能在模型回调中编写控制器代码吗,比如“@list=Coupons.all”是的,你可以写……但是回调的目的不同…………要了解更多信息,请检查这里,糟糕!现在明白了,Thxbtw,jus好奇我能在after_save回调中查询记录吗?我的意思是我能在模型回调中编写控制器代码吗,比如“@list=Coupons.all”是的,你可以写……但是回调的目的不同…………更多信息请查看这里