Module: HasPermalink::ClassMethods

Defined in:
lib/has_permalink.rb

Instance Method Summary collapse

Instance Method Details



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/has_permalink.rb', line 9

def has_permalink column, options={}
  extend FriendlyId

  friendly_id column do |config|
    config.use :slugged, :finders
    if options[:scope]
      config.use :scoped
      config.scope = options[:scope]
    end
    config.slug_column = options[:url_attribute]
  end

  self.class_eval do
    def should_generate_new_friendly_id?
      permalink.blank?
    end
  end

  define_method :"#{options[:url_attribute]}=" do |value|
    value = value.parameterize if value
    super value
  end
end