Module: Permalink::ActiveRecord::ClassMethods

Defined in:
lib/permalink/active_record.rb

Instance Method Summary collapse

Instance Method Details

permalink :title permalink :title, :to => :custom_permalink_field permalink :title, :to => :permalink, :to_param => [:id, :permalink] permalink :title, :unique => true



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/permalink/active_record.rb', line 14

def permalink(from_column, options = {})
  include InstanceMethods

  options.reverse_merge!({
    to_param: [:id, :permalink],
    to: :permalink,
    unique: false,
    force: false
  })

  self.permalink_options = {
    from_column_name: from_column,
    to_column_name: options[:to],
    to_param: [options[:to_param]].flatten,
    unique: options[:unique],
    force: options[:force],
    scope: options[:scope]
  }

  before_validation :create_permalink
  before_save :create_permalink
end