Ajey
Ajey

Reputation: 8202

Rails after_save error

Is this the correct way of using after_save callback ?

class CouponsController < ApplicationController
after_save :remove_restrictions
 private
    def remove_restrictions

      logger.debug("in after save")
    end

end

This code throws the error as

undefined method `after_save' for CouponsController:Class

What is the correct way of using after_save ?

Upvotes: 1

Views: 2260

Answers (1)

LHH
LHH

Reputation: 3323

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

app/controllers/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

Upvotes: 6

Related Questions