Created
August 17, 2020 23:21
-
-
Save bearded-avenger/b2747f40c3526efbbc55720fe9a54634 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GiftCard < ApplicationRecord | |
belongs_to :site | |
belongs_to :subscription_plan, optional: true | |
acts_as_tenant :site | |
include ProductConcern | |
include ImageUploader[:image] | |
enum status: { draft:0, published:1} | |
validates_presence_of :title | |
validates_uniqueness_to_tenant :slug | |
before_create :set_slug | |
validates_presence_of :slug, on: :update | |
accepts_nested_attributes_for :product, allow_destroy: true | |
validates_associated :product | |
has_many :gift_card_purchases, dependent: :destroy | |
def to_param | |
slug | |
end | |
private | |
def set_slug | |
newSlug = self.site.gift_cards.exists?(slug:title.parameterize) ? "#{title.parameterize}-#{SecureRandom.hex(8)}" : title.parameterize | |
self.slug = newSlug | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GiftCardPurchase < ApplicationRecord | |
belongs_to :site | |
belongs_to :gift_card | |
belongs_to :coupon | |
acts_as_tenant :site | |
validates_presence_of :recipient_name | |
validates_presence_of :recipient_email, format: Devise.email_regexp | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment