Sha256: 30c50755f75e2e26725d62da665c479353f69c5c298c407e500215dab12997e9

Contents?: true

Size: 691 Bytes

Versions: 10

Compression:

Stored size: 691 Bytes

Contents

require 'redde/url_generator'

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

10 entries across 10 versions & 1 rubygems

Version Path
redde-0.1.18 lib/redde/concerns/sluggable.rb
redde-0.1.17 lib/redde/concerns/sluggable.rb
redde-0.1.16 lib/redde/concerns/sluggable.rb
redde-0.1.15 lib/redde/concerns/sluggable.rb
redde-0.1.14 lib/redde/concerns/sluggable.rb
redde-0.1.13 lib/redde/concerns/sluggable.rb
redde-0.1.12 lib/redde/concerns/sluggable.rb
redde-0.1.11 lib/redde/concerns/sluggable.rb
redde-0.1.10 lib/redde/concerns/sluggable.rb
redde-0.1.9 lib/redde/sluggable.rb