Module: Adva::HasPermalink::ClassMethods

Defined in:
lib/adva/has_permalink.rb

Instance Method Summary collapse

Instance Method Details



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

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