Module: HasFriendlyName::InstanceMethods

Defined in:
lib/has_friendly_name.rb

Instance Method Summary collapse

Instance Method Details

#generate_friendly_nameObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/has_friendly_name.rb', line 40

def generate_friendly_name              
  self.friendly_name = send(self.has_friendly_name_options[:from].to_s.to_sym).to_friendly(self.has_friendly_name_options)
  
  if self.has_friendly_name_options[:unique] 
    checkmodel=self.class.find(:first, :conditions => "friendly_name='#{self.friendly_name}'")          
    if checkmodel and checkmodel!=self
      self.friendly_name+='-'+(self.class.count+1).to_s
    end
  end
      
  self.friendly_name
end