Sha256: 3977594754db9df10508aad86af9dd68a2ad3bd67cf27aaa868e55d585d8d60a
Contents?: true
Size: 948 Bytes
Versions: 3
Compression:
Stored size: 948 Bytes
Contents
module FriendlySlug module ActiveRecord module Base def build_friendly_slug(first_attribute_key, second_attribute_key) instance_variable_set("@first_attribute_key", first_attribute_key) instance_variable_set("@second_attribute_key", second_attribute_key) instance_eval do def first_attribute_key @first_attribute_key end def second_attribute_key @second_attribute_key end end class_eval do def to_param "#{lookup_key(self.class.first_attribute_key)}-#{lookup_key(self.class.second_attribute_key)}".to_s.gsub(/<\/?[^>]*>|[^\w\s-]/, '').strip.downcase.gsub(/\s/, '-') end private def lookup_key(k) k.is_a?(Symbol)? self.send(k) : k.to_s end end end end end end class ActiveRecord::Base extend FriendlySlug::ActiveRecord::Base end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
friendly_slug-0.1.3 | lib/friendly_slug/active_record/base.rb |
friendly_slug-0.1.2 | lib/friendly_slug/active_record/base.rb |
friendly_slug-0.1.1 | lib/friendly_slug/active_record/base.rb |