Permalink
Browse files

Include cache key in ModelName

  • Loading branch information...
1 parent 6874caa commit 071fe79279e89e650acce6613f13027527d01650 @jeremy jeremy committed Jun 25, 2008
@@ -2170,11 +2170,11 @@ def to_param
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
@@ -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

0 comments on commit 071fe79

Please sign in to comment.