Sha256: 7bdb246f2dedcbe6c53080faee3b4694b0c108819af4886b5a6b213f64a75f49
Contents?: true
Size: 954 Bytes
Versions: 5
Compression:
Stored size: 954 Bytes
Contents
module Pseudocephalopod module SlugHistory extend ActiveSupport::Concern included do after_save :record_slug_changes after_destroy :remove_slug_history! end module InstanceMethods def previous_slugs Pseudocephalopod.previous_slugs_for(self) end def remove_slug_history! Pseudocephalopod.remove_slug_history_for(self) end protected def record_slug_changes slug_column = self.cached_slug_column return unless send(:"#{slug_column}_changed?") value = send(:"#{slug_column}_was") Pseudocephalopod.record_slug(self, value) if value.present? end end module ClassMethods def find_using_slug_history(slug, options = {}) id = Pseudocephalopod.last_known_slug_id(self, slug) id.present? ? find_by_id(id, options) : nil end end end end
Version data entries
5 entries across 5 versions & 1 rubygems