Sha256: e68c70b02f3bf37d7758012b8c1ca218c5951a53e2dfbc64ec22651a8b2d37a4
Contents?: true
Size: 1.01 KB
Versions: 10
Compression:
Stored size: 1.01 KB
Contents
class Taxon < ActiveRecord::Base acts_as_adjacency_list :foreign_key => 'parent_id', :order => 'position' belongs_to :taxonomy has_and_belongs_to_many :products before_save :set_permalink private def set_permalink ancestors.reverse.collect { |ancestor| ancestor.name }.join( "/") prefix = ancestors.reverse.collect { |ancestor| escape(ancestor.name) }.join( "/") prefix += "/" unless prefix.blank? self.permalink = prefix + "#{escape(name)}/" end # taken from the find_by_param plugin def escape(str) return "" if str.blank? # hack if the str/attribute is nil/blank s = Iconv.iconv('ascii//ignore//translit', 'utf-8', str.dup).to_s returning str.dup.to_s do |s| s.gsub!(/\ +/, '-') # spaces to dashes, preferred separator char everywhere s.gsub!(/[^\w^-]+/, '') # kill non-word chars except - s.strip! # ohh la la s.downcase! # :D s.gsub!(/([^ a-zA-Z0-9_-]+)/n,"") # and now kill every char not allowed. end end end
Version data entries
10 entries across 10 versions & 2 rubygems