Sha256: e94cd0dbb40cc3a615981d9811f76a1ca2b98701018b47d5e59847563cb5896a

Contents?: true

Size: 609 Bytes

Versions: 170

Compression:

Stored size: 609 Bytes

Contents

module ManualSlug::ActiveRecord
  extend ActiveSupport::Concern

  included do
    extend FriendlyId
  end

  def text_slug
    slug
  end
  def text_slug=(s)
    self.slug = s
  end

  module ClassMethods
    def manual_slug(field, options = {}, callback = true)
      friendly_id field, use: [:slugged, :finders]
      define_method(:should_generate_new_friendly_id?) do
        slug.blank?
      end

      skip_callback :validation, :before, :set_slug
      before_validation do
        if self.slug.blank?
          self.send(:set_slug)
        end
        true
      end if callback
    end
  end
end
 

Version data entries

170 entries across 170 versions & 4 rubygems

Version Path
rocket_cms-0.17.0 lib/manual_slug/active_record.rb
hancock_cms-1.0.1 lib/manual_slug/active_record.rb
hancock_cms-2.0.0.2 lib/manual_slug/active_record.rb
hancock_cms-1.0.0.4 lib/manual_slug/active_record.rb
hancock_cms-1.0.0.3 lib/manual_slug/active_record.rb
hancock_cms-2.0.0.1 lib/manual_slug/active_record.rb
hancock_cms-1.0.0.2 lib/manual_slug/active_record.rb
hancock_cms-2.0.0 lib/manual_slug/active_record.rb
hancock_cms-1.0.0 lib/manual_slug/active_record.rb
rocket_cms-0.16.1 lib/manual_slug/active_record.rb
rocket_cms-0.16.0 lib/manual_slug/active_record.rb
rocket_cms-0.15.5 lib/manual_slug/active_record.rb
rocket_cms-0.15.4 lib/manual_slug/active_record.rb
rocket_cms-0.15.3 lib/manual_slug/active_record.rb
rocket_cms-0.15.2 lib/manual_slug/active_record.rb
rocket_cms-0.15.1 lib/manual_slug/active_record.rb
rocket_cms-0.15.0 lib/manual_slug/active_record.rb
enjoy_cms-0.4.1 lib/manual_slug/active_record.rb
rocket_cms-0.14.0 lib/manual_slug/active_record.rb
enjoy_cms-0.4.0.5 lib/manual_slug/active_record.rb