Sha256: ab6586b49cc02006948ee5f5dad582db62a6792abf9278ed409259fdb16e4bb7

Contents?: true

Size: 735 Bytes

Versions: 45

Compression:

Stored size: 735 Bytes

Contents

module Redde::Sluggable
  extend ActiveSupport::Concern

  included do
    validates :slug,
              format: {
                with: /\A[A-z0-9_-]*\z/i,
                message: 'имеет неверный формат, разрешены английские символы, знак подчеркивания "_" и дефис "-"'
              },
              presence: true
    before_validation :set_slug
  end

  def set_slug
    self.slug = Redde::UrlGenerator.new(self, title_field).formatted_name.downcase unless slug.present?
  end

  def title_field
    send(title_symbol)
  end

  def title_symbol
    self.class::TITLE_SYMBOL
  rescue
    :title
  end

  def to_param
    "#{id}-#{slug.try(:downcase)}"
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
redde-0.4.4 app/models/concerns/redde/sluggable.rb
redde-0.4.3 app/models/concerns/redde/sluggable.rb
redde-0.4.2 app/models/concerns/redde/sluggable.rb
redde-0.4.1 app/models/concerns/redde/sluggable.rb
redde-0.4.0 app/models/concerns/redde/sluggable.rb
redde-0.3.39 app/models/concerns/redde/sluggable.rb
redde-0.3.38 app/models/concerns/redde/sluggable.rb
redde-0.3.37 app/models/concerns/redde/sluggable.rb
redde-0.3.36 app/models/concerns/redde/sluggable.rb
redde-0.3.35 app/models/concerns/redde/sluggable.rb
redde-0.3.34 app/models/concerns/redde/sluggable.rb
redde-0.3.33 app/models/concerns/redde/sluggable.rb
redde-0.3.32 app/models/concerns/redde/sluggable.rb
redde-0.3.31 app/models/concerns/redde/sluggable.rb
redde-0.3.30 app/models/concerns/redde/sluggable.rb
redde-0.3.29 app/models/concerns/redde/sluggable.rb
redde-0.3.28 app/models/concerns/redde/sluggable.rb
redde-0.3.27 app/models/concerns/redde/sluggable.rb
redde-0.3.26 app/models/concerns/redde/sluggable.rb
redde-0.3.25 app/models/concerns/redde/sluggable.rb