“After_create for STI Rails” Kod odpowiedzi

After_create for STI Rails

after_create : create_coupons_for_existing_users, unless: :discounted_coupon?
Annoying Armadillo

After_create for STI Rails

module Concerns::CouponDistribution
  extend ActiveSupport::Concern

  included do
    after_create :create_coupons_for_existing_users, if: Proc.new {|cd| cd.type == "DiscountedCoupon" }
  end

  def create_coupons_for_existing_users
    #
  end

end
Annoying Armadillo

After_create for STI Rails

def create_coupons_for_existing_users
  return unless self.type == "DiscountedCoupon"
  # your logic here
end
Annoying Armadillo

After_create for STI Rails

def discounted_coupon?
  self.type == "DiscountedCoupon"
end 
Annoying Armadillo

Odpowiedzi podobne do “After_create for STI Rails”

Pytania podobne do “After_create for STI Rails”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu