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.21.1 lib/manual_slug/active_record.rb
rocket_cms-0.21.0 lib/manual_slug/active_record.rb
rocket_cms-0.20.1 lib/manual_slug/active_record.rb
rocket_cms-0.20.0 lib/manual_slug/active_record.rb
rocket_cms-0.19.8 lib/manual_slug/active_record.rb
rocket_cms-0.19.7 lib/manual_slug/active_record.rb
rocket_cms-0.19.6 lib/manual_slug/active_record.rb
rocket_cms-0.19.4 lib/manual_slug/active_record.rb
rocket_cms-0.19.3 lib/manual_slug/active_record.rb
rocket_cms-0.19.2 lib/manual_slug/active_record.rb
rocket_cms-0.19.1 lib/manual_slug/active_record.rb
rocket_cms-0.19.0 lib/manual_slug/active_record.rb
rocket_cms-0.18.5 lib/manual_slug/active_record.rb
rocket_cms-0.18.4 lib/manual_slug/active_record.rb
rocket_cms-0.18.3 lib/manual_slug/active_record.rb
rocket_cms-0.18.2 lib/manual_slug/active_record.rb
rocket_cms-0.18.1 lib/manual_slug/active_record.rb
rocket_cms-0.18.0 lib/manual_slug/active_record.rb
rocket_cms-0.17.2 lib/manual_slug/active_record.rb
rocket_cms-0.17.1 lib/manual_slug/active_record.rb