Sha256: 9bbec8a3232bab76253dface8c48b31ab9231b90c8f328d99b7427762d67934e

Contents?: true

Size: 892 Bytes

Versions: 6

Compression:

Stored size: 892 Bytes

Contents

module ActiveRecord
  module Acts
    module Sluggy
      def self.included(base)
        base.extend(ClassMethods)
      end

      module ClassMethods

        def has_slug(options = {})
          configuration = { :attribute => "title", :to_param => "slug", :to_url => "parameterize" }
          configuration.update(options) if options.is_a?(Hash)

          before_save :update_slug
          to_param = case configuration[:to_param]
          when :id_slug
            "id.to_s + '-' + slug"
          else
            configuration[:to_param]
          end
            class_eval <<-EOV
            def to_param
              #{to_param}
            end

            def update_slug
              self.slug = self.#{configuration[:attribute]}.#{configuration[:to_url]}
            end
            EOV
          end
        end
      end
    end
  end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
etabliocms_core-0.0.7 vendor/plugins/acts_as_sluggy/lib/active_record/acts/sluggy.rb
etabliocms_core-0.0.6 vendor/plugins/acts_as_sluggy/lib/active_record/acts/sluggy.rb
etabliocms_core-0.0.5 vendor/plugins/acts_as_sluggy/lib/active_record/acts/sluggy.rb
etabliocms_core-0.0.4 vendor/plugins/acts_as_sluggy/lib/active_record/acts/sluggy.rb
etabliocms_core-0.0.3 vendor/plugins/acts_as_sluggy/lib/active_record/acts/sluggy.rb
etabliocms_core-0.0.2 vendor/plugins/acts_as_sluggy/lib/active_record/acts/sluggy.rb