From 70a440aa277676078e3b8baafe1101d1287e114f Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Fri, 7 Aug 2009 00:52:13 -0300 Subject: Clean up render @object a bit more. --- .../lib/action_controller/record_identifier.rb | 15 ------------- actionpack/lib/action_view/render/partials.rb | 25 ++++++++++++++++------ 2 files changed, 19 insertions(+), 21 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/record_identifier.rb b/actionpack/lib/action_controller/record_identifier.rb index b4408e4e1d..1165c3b7c5 100644 --- a/actionpack/lib/action_controller/record_identifier.rb +++ b/actionpack/lib/action_controller/record_identifier.rb @@ -36,21 +36,6 @@ module ActionController JOIN = '_'.freeze NEW = 'new'.freeze - # Returns plural/singular for a record or class. Example: - # - # partial_path(post) # => "posts/post" - # partial_path(Person) # => "people/person" - # partial_path(Person, "admin/games") # => "admin/people/person" - def partial_path(record_or_class, controller_path = nil) - name = model_name_from_record_or_class(record_or_class) - - if controller_path && controller_path.include?("/") - "#{File.dirname(controller_path)}/#{name.partial_path}" - else - name.partial_path - end - end - # The DOM class convention is to use the singular form of an object or class. Examples: # # dom_class(post) # => "post" diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index 581742e875..6e5810d148 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -177,6 +177,12 @@ module ActionView attr_accessor :_partial end + module ClassMethods + def _partial_names + @_partial_names ||= ActiveSupport::ConcurrentHash.new + end + end + def render_partial(*args) @assigns_added = false _render_partial(*args) @@ -189,12 +195,9 @@ module ActionView if partial.respond_to?(:to_ary) return _render_partial_collection(partial, options) - elsif partial.is_a?(ActionView::Helpers::FormBuilder) - path = partial.class.model_name.partial_path - options[:locals].merge!(path.to_sym => partial) elsif !partial.is_a?(String) options[:object] = object = partial - path = ActionController::RecordIdentifier.partial_path(object, controller_path) + path = _partial_path(object) end parts = partial_parts(path, options) @@ -203,6 +206,17 @@ module ActionView end private + def _partial_path(object) + self.class._partial_names[[controller.class, object.class]] ||= begin + name = object.class.model_name + if controller_path && controller_path.include?("/") + File.join(File.dirname(controller_path), name.partial_path) + else + name.partial_path + end + end + end + def partial_parts(name, options) segments = name.split("/") parts = segments.pop.split(".") @@ -278,8 +292,7 @@ module ActionView index, @_partial_path = 0, nil collection.map do |object| options[:_template] = template = passed_template || begin - _partial_path = - ActionController::RecordIdentifier.partial_path(object, controller_path) + _partial_path = _partial_path(object) template = _pick_partial_template(_partial_path) end -- cgit v1.2.3