aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorGaston Ramos <ramos.gaston@gmail.com>2011-07-23 20:49:16 -0300
committerGaston Ramos <ramos.gaston@gmail.com>2011-07-24 00:54:58 -0300
commitdc1b0fd957246a05f7b490aa03970bcdcc9c48ba (patch)
tree112d8809d2a22f1a00dd0fd3788361df1a575c32 /actionpack
parent7621d131d2b8f7b65f7f06615e6714d8f4605439 (diff)
downloadrails-dc1b0fd957246a05f7b490aa03970bcdcc9c48ba.tar.gz
rails-dc1b0fd957246a05f7b490aa03970bcdcc9c48ba.tar.bz2
rails-dc1b0fd957246a05f7b490aa03970bcdcc9c48ba.zip
- added ActionView::PartialRenderer#merge_path_into_partial(path, partial)
fix issues/1951
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/renderer/partial_renderer.rb18
-rw-r--r--actionpack/test/controller/render_test.rb2
2 files changed, 17 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb
index 51c784493e..c0ac332c4e 100644
--- a/actionpack/lib/action_view/renderer/partial_renderer.rb
+++ b/actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -362,14 +362,28 @@ module ActionView
def partial_path(object = @object)
@partial_names[object.class.name] ||= begin
object = object.to_model if object.respond_to?(:to_model)
-
object.class.model_name.partial_path.dup.tap do |partial|
path = @lookup_context.prefixes.first
- partial.insert(0, "#{File.dirname(path)}/") if partial.include?(?/) && path.include?(?/)
+ merge_path_into_partial(path, partial)
end
end
end
+ def merge_path_into_partial(path, partial)
+ if path.include?(?/) && partial.include?(?/)
+ overlap = []
+ path_array = File.dirname(path).split('/')
+ partial_array = partial.split('/')[0..-3] # skip model dir & partial
+
+ path_array.each_with_index do |dir, index|
+ overlap << dir if dir == partial_array[index]
+ end
+
+ partial.gsub!(/^#{overlap.join('/')}\//,'')
+ partial.insert(0, "#{File.dirname(path)}/")
+ end
+ end
+
def retrieve_variable(path)
variable = @options[:as].try(:to_sym) || path[%r'_?(\w+)(\.\w+)*$', 1].to_sym
variable_counter = :"#{variable}_counter" if @collection
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 99d6be7af3..ce4b407c7d 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -17,7 +17,7 @@ end
module Quiz
class QuestionsController < ActionController::Base
def new
- render :partial => Quiz::Question.new(:name => "Bruce Lee")
+ render :partial => Quiz::Question.new("Namespaced Partial")
end
end
end