* Improved article slug generation Ruby on Rails has a built-in slug generator since Rails 2.2 This generator fix the slug generation when non english characters are used on title improving SEO. For example: https://dev.to/lito_ordes/redimensionando-imgenes-en-tiempo-de-ejecucin-con-packer-57c6 * Ruby on Rails has a built-in slug generator since Rails 2.2 This generator fix the slug generation when non english characters are used on title improving SEO. For example: https://dev.to/lito_ordes/redimensionando-imgenes-en-tiempo-de-ejecucin-con-packer-57c6 * Ruby on Rails has a built-in slug generator since Rails 2.2 This generator fix the slug generation when non english characters are used on title improving SEO. For example: https://dev.to/lito_ordes/redimensionando-imgenes-en-tiempo-de-ejecucin-con-packer-57c6 * Ruby on Rails has a built-in slug generator since Rails 2.2 This generator fix the slug generation when non english characters are used on title improving SEO. For example: https://dev.to/lito_ordes/redimensionando-imgenes-en-tiempo-de-ejecucin-con-packer-57c6 * Ruby on Rails has a built-in slug generator since Rails 2.2 This generator fix the slug generation when non english characters are used on title improving SEO. For example: https://dev.to/lito_ordes/redimensionando-imgenes-en-tiempo-de-ejecucin-con-packer-57c6 * Fix downcase transform on event model
29 lines
595 B
Ruby
29 lines
595 B
Ruby
class Badge < ApplicationRecord
|
|
mount_uploader :badge_image, BadgeUploader
|
|
|
|
has_many :badge_achievements
|
|
has_many :users, through: :badge_achievements
|
|
|
|
validates :title, presence: true, uniqueness: true
|
|
validates :description, presence: true
|
|
validates :badge_image, presence: true
|
|
|
|
before_validation :generate_slug
|
|
after_save :bust_path
|
|
|
|
def path
|
|
"/badge/#{slug}"
|
|
end
|
|
|
|
private
|
|
|
|
def generate_slug
|
|
self.slug = title.to_s.parameterize
|
|
end
|
|
|
|
def bust_path
|
|
cache_buster = CacheBuster.new
|
|
cache_buster.bust path
|
|
cache_buster.bust path + "?i=i"
|
|
end
|
|
end
|