Class: Taxon
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Taxon
- Defined in:
- app/models/taxon.rb
Instance Method Summary collapse
-
#set_path ⇒ Object
Creates path based on .to_url method provided by stringx gem.
- #set_root ⇒ Object
- #set_taxonomy ⇒ Object
Instance Method Details
#set_path ⇒ Object
Creates path based on .to_url method provided by stringx gem
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/taxon.rb', line 20 def set_path if self.root? self.path = '/' else ancestor_path = parent_taxon.path rescue "/" sep = ancestor_path == "/" ? "" : "/" self.path = ancestor_path + sep + self.url end #if parent_id.nil? #self.path = self.url if self.path.blank? #else #parent_taxon = Taxon.find(parent_id) #self.path = [parent_taxon.path, (self.path.blank? ? name.to_url : self.path.split("/").last)].join('/') #end end |
#set_root ⇒ Object
45 46 47 48 |
# File 'app/models/taxon.rb', line 45 def set_root self.root_id = self.id if self.root? save end |
#set_taxonomy ⇒ Object
38 39 40 41 42 43 |
# File 'app/models/taxon.rb', line 38 def set_taxonomy if ! self.root? self.root_id = parent_taxon.root_id self.taxonomy_id = parent_taxon.taxonomy_id end end |