1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Include cache key in ModelName

This commit is contained in:
Jeremy Kemper 2008-06-24 22:07:09 -07:00
parent 6874caa407
commit 071fe79279
2 changed files with 7 additions and 6 deletions

View file

@ -2170,11 +2170,11 @@ module ActiveRecord #:nodoc:
def cache_key
case
when new_record?
"#{self.class.name.tableize}/new"
when self[:updated_at]
"#{self.class.name.tableize}/#{id}-#{updated_at.to_s(:number)}"
"#{self.class.model_name.cache_key}/new"
when timestamp = self[:updated_at]
"#{self.class.model_name.cache_key}/#{id}-#{timestamp.to_s(:number)}"
else
"#{self.class.name.tableize}/#{id}"
"#{self.class.model_name.cache_key}/#{id}"
end
end

View file

@ -1,12 +1,13 @@
module ActiveSupport
class ModelName < String
attr_reader :singular, :plural, :partial_path
attr_reader :singular, :plural, :cache_key, :partial_path
def initialize(name)
super
@singular = underscore.tr('/', '_').freeze
@plural = @singular.pluralize.freeze
@partial_path = "#{tableize}/#{demodulize.underscore}".freeze
@cache_key = tableize
@partial_path = "#{@cache_key}/#{demodulize.underscore}".freeze
end
end