21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/railhead_permalink.rb', line 21
def auto_permalink(field, options = {})
include RailheadPermalink::InstanceMethods
class << self
alias_method_chain :find, :permalink
end
class_attribute :permalink_options
self.permalink_options = {
:field => field,
:keep_existing => (options[:keep_existing] || false),
:reserved_names => (options[:reserved_names] || []),
:unique => (options[:unique] || false)
}
before_save :create_permalink
validates_presence_of field
validates_uniqueness_of field, :case_sensitive => false, :if => "#{field}_changed?".to_sym if permalink_options[:unique]
end
|