diff options
author | Yehuda Katz <wycats@gmail.com> | 2009-08-06 23:42:11 -0300 |
---|---|---|
committer | Yehuda Katz <wycats@gmail.com> | 2009-08-06 23:42:11 -0300 |
commit | 4ac9d391d337d5a05a7aa93849405e21dd4bbf01 (patch) | |
tree | 1b37c4b395f8d2f43fc453c5c2cd06ff7b59ddc2 /actionpack/lib/action_view/render/partials.rb | |
parent | 0435178ff896e9b3854cb53cbd9fbd33a8f78209 (diff) | |
download | rails-4ac9d391d337d5a05a7aa93849405e21dd4bbf01.tar.gz rails-4ac9d391d337d5a05a7aa93849405e21dd4bbf01.tar.bz2 rails-4ac9d391d337d5a05a7aa93849405e21dd4bbf01.zip |
Improve a path in _render_partial
Diffstat (limited to 'actionpack/lib/action_view/render/partials.rb')
-rw-r--r-- | actionpack/lib/action_view/render/partials.rb | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/actionpack/lib/action_view/render/partials.rb b/actionpack/lib/action_view/render/partials.rb index 8bdff0f3b9..581742e875 100644 --- a/actionpack/lib/action_view/render/partials.rb +++ b/actionpack/lib/action_view/render/partials.rb @@ -172,9 +172,9 @@ module ActionView module Partials extend ActiveSupport::Memoizable extend ActiveSupport::Concern - + included do - attr_accessor :_partial + attr_accessor :_partial end def render_partial(*args) @@ -185,22 +185,21 @@ module ActionView def _render_partial(options = {}) #:nodoc: options[:locals] ||= {} - case path = partial = options[:partial] - when *_array_like_objects + path = partial = options[:partial] + + if partial.respond_to?(:to_ary) return _render_partial_collection(partial, options) - else - if partial.is_a?(ActionView::Helpers::FormBuilder) - path = partial.class.to_s.demodulize.underscore.sub(/_builder$/, '') - options[:locals].merge!(path.to_sym => partial) - elsif !partial.is_a?(String) - options[:object] = object = partial - path = ActionController::RecordIdentifier.partial_path(object, controller_path) - end - _, _, prefix, object = parts = partial_parts(path, options) - parts[1] = {:formats => parts[1]} - template = find_by_parts(*parts) - _render_partial_object(template, options, (object unless object == true)) + 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) end + + parts = partial_parts(path, options) + template = find_by_parts(*parts) + _render_partial_object(template, options, (parts[3] unless parts[3] == true)) end private @@ -222,7 +221,7 @@ module ActionView path = parts.join(".") prefix = segments[0..-1].join("/") prefix = prefix.blank? ? controller_path : prefix - parts = [path, formats, prefix] + parts = [path, {:formats => formats}, prefix] parts.push options[:object] || true end @@ -256,11 +255,11 @@ module ActionView else locals = (options[:locals] ||= {}) object ||= locals[:object] || locals[template.variable_name] - + _set_locals(object, locals, template, options) - + options[:_template] = template - + _render_template(template, locals) end end @@ -272,23 +271,23 @@ module ActionView def _render_partial_collection(collection, options = {}, passed_template = nil) #:nodoc: return nil if collection.blank? - + spacer = options[:spacer_template] ? _render_partial(:partial => options[:spacer_template]) : '' locals = (options[:locals] ||= {}) index, @_partial_path = 0, nil collection.map do |object| options[:_template] = template = passed_template || begin - _partial_path = + _partial_path = ActionController::RecordIdentifier.partial_path(object, controller_path) template = _pick_partial_template(_partial_path) end _set_locals(object, locals, template, options) locals[template.counter_name] = index - + index += 1 - + _render_template(template, locals) end.join(spacer) end |