Sha256: 6049fcf73b31c196dd9bdcd74e1a0f2b729db354bf1a1de19eaab7cd9d0047d6

Contents?: true

Size: 623 Bytes

Versions: 5

Compression:

Stored size: 623 Bytes

Contents

module Adminos::Slugged
  extend ActiveSupport::Concern

  module ClassMethods
    def slugged(*args)
      options = args.extract_options!
      sluggable_column = args.first || options.delete(:sluggable_column) || :name
      slug_column      = options.delete(:slug_column) || :slug
      validate = options.fetch(:validates, true)

      before_validation do |object|
        if object.send sluggable_column
          object[slug_column] = object.send(sluggable_column).parameterize
        end
      end

      validates(slug_column, presence: true, format: { with: /\A[a-zA-Z0-9-]+\z/ }) if validate
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
adminos-1.0.0.pre.rc.5 lib/adminos/helpers/models/slugged.rb
adminos-1.0.0.pre.rc.4 lib/adminos/helpers/models/slugged.rb
adminos-1.0.0.pre.rc.3 lib/adminos/helpers/models/slugged.rb
adminos-1.0.0.pre.rc.2 lib/adminos/helpers/models/slugged.rb
adminos-1.0.0.pre.rc.1 lib/adminos/helpers/models/slugged.rb