* Add missing presence validator for Tag * Add missing presence validators to Follow * Add missing presence validators to ProfileField * Add missing presence validators to Comment * Add missing presence validators to Profile * Add missing presence validators to Organization * Add missing presence validators to Badge * Add missing presence validators to Webhook::Endpoint * Add missing presence validators to NotificationSubscription * Add missing presence validators to PodcastEpisode * Add missing presence validators to Sponsorship * Add missing presence validators to PollOption * Add missing presence validators to Poll * Add missing presence validators to Article * Add missing presence validators to EmailAuthorization * Add missing presence validators to AuditLog * Add missing presence validators to DataUpdateScript * Add missing presence validators to User * Add missing presence validators to SiteConfig * Fix specs
31 lines
702 B
Ruby
31 lines
702 B
Ruby
class Badge < ApplicationRecord
|
|
mount_uploader :badge_image, BadgeUploader
|
|
resourcify
|
|
|
|
has_many :badge_achievements, dependent: :restrict_with_error
|
|
has_many :tags, dependent: :restrict_with_error
|
|
has_many :users, through: :badge_achievements
|
|
|
|
validates :badge_image, presence: true
|
|
validates :description, presence: true
|
|
validates :slug, presence: true
|
|
validates :title, presence: true, uniqueness: true
|
|
|
|
before_validation :generate_slug
|
|
after_save :bust_path
|
|
|
|
def path
|
|
"/badge/#{slug}"
|
|
end
|
|
|
|
private
|
|
|
|
def generate_slug
|
|
self.slug = CGI.escape(title.to_s).parameterize
|
|
end
|
|
|
|
def bust_path
|
|
CacheBuster.bust(path)
|
|
CacheBuster.bust("#{path}?i=i")
|
|
end
|
|
end
|