“After_create para Rails STI” Respostas de código

After_create para Rails STI

after_create : create_coupons_for_existing_users, unless: :discounted_coupon?
Annoying Armadillo

After_create para Rails STI

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 para Rails STI

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

After_create para Rails STI

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

Respostas semelhantes a “After_create para Rails STI”

Perguntas semelhantes a “After_create para Rails STI”

Procure respostas de código populares por idioma

Procurar outros idiomas de código