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 permalink :title, separator: “_” permalink :title, normalizations: array_of_normalizations



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/permalink/active_record.rb', line 16

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

  options = options.reverse_merge({
    to_param: [:id, :permalink],
    to: :permalink,
    unique: false,
    force: false,
    separator: "-",
    normalizations: Permalink::DEFAULT_NORMALIZATIONS
  })

  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],
    separator: options[:separator],
    normalizations: options[:normalizations]
  }

  before_validation :create_permalink
  before_save :create_permalink
end