aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xactiverecord/lib/active_record/base.rb8
-rw-r--r--activesupport/lib/active_support/core_ext/module/model_naming.rb5
2 files changed, 7 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index e6ab87e8fc..021aaf4ca1 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -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
diff --git a/activesupport/lib/active_support/core_ext/module/model_naming.rb b/activesupport/lib/active_support/core_ext/module/model_naming.rb
index 26e76ab556..abb02f1f70 100644
--- a/activesupport/lib/active_support/core_ext/module/model_naming.rb
+++ b/activesupport/lib/active_support/core_ext/module/model_naming.rb
@@ -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