docbrown/app/models/badge.rb
Lito 2ebd37aba2 Improved article slug generation (#2218)
* 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
2019-03-26 13:39:35 -04:00

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