Sha256: ca57e1e79c163179cc82549c9706e5bf4f3268108758ea57d8547260a6a945ee
Contents?: true
Size: 488 Bytes
Versions: 6
Compression:
Stored size: 488 Bytes
Contents
module PrettyUrl extend ActiveSupport::Concern included do after_save :update_url_name end module ClassMethods def find(id, options = {}) if id.is_a?(String) real_id = /(.*\-)?(?<id>\d+)\Z/.match(id)[:id] else real_id = id end super(real_id, options) end end def to_param url_name end private def update_url_name self.url_name = "#{name.to_url}-#{id}" if name_changed? and !url_name_changed? end end
Version data entries
6 entries across 6 versions & 1 rubygems