Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

- added ActionView::PartialRenderer#merge_path_into_partial(path, par…

…tial)

  fix issues/1951
  • Loading branch information...
commit 8d0e3c9dc27dd5b3c9fb4c5fe73ff77814c6af53 1 parent 1f3f9f1
@gramos gramos authored
View
18 actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -357,14 +357,28 @@ def collection_without_template
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
View
2  actionpack/test/controller/render_test.rb
@@ -17,7 +17,7 @@ def nested_partial_with_form_builder
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
Please sign in to comment.
Something went wrong with that request. Please try again.