module RailheadPermalink::InstanceMethods
Public Instance Methods
create_permalink()
click to toggle source
# File lib/railhead_permalink.rb, line 60 def create_permalink if self.permalink.nil? or (self.changed.include?(permalink_options[:field].to_s) and not permalink_options[:keep_existing]) key = self.send(permalink_options[:field]).to_url unless self.permalink == key permalink, counter = key, '-1' while permalink_options[:reserved_names].include?(permalink) or permalink.blank? or (object = self.class.where(permalink: permalink).first and object != self) counter.succ! permalink = key + counter end self.permalink = permalink end end true end
to_param()
click to toggle source
# File lib/railhead_permalink.rb, line 76 def to_param self.permalink end