diff options
author | José Valim <jose.valim@gmail.com> | 2012-03-28 23:51:34 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-03-28 23:51:34 -0700 |
commit | e51322a34b740a4ad3b651345e2420912fe2a15f (patch) | |
tree | c9d93d3933893f04534b5810a806b1dcf7e9663e /actionpack/lib | |
parent | e83e76eca4e134c91c4c2c1092b41f4483592172 (diff) | |
parent | 18d275ada1b23bf07cc51a815385afac6bb2b8cb (diff) | |
download | rails-e51322a34b740a4ad3b651345e2420912fe2a15f.tar.gz rails-e51322a34b740a4ad3b651345e2420912fe2a15f.tar.bz2 rails-e51322a34b740a4ad3b651345e2420912fe2a15f.zip |
Merge pull request #5625 from nertzy/prefix_partial_path_with_controller_namespace
Add config option to turn off prefixing partial path with controller namespace
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/base.rb | 6 | ||||
-rw-r--r-- | actionpack/lib/action_view/renderer/partial_renderer.rb | 13 |
2 files changed, 16 insertions, 3 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index 23329d7f35..056dbc9529 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -141,6 +141,12 @@ module ActionView #:nodoc: cattr_accessor :streaming_completion_on_exception @@streaming_completion_on_exception = %("><script type="text/javascript">window.location = "/500.html"</script></html>) + # Specify whether rendering within namespaced controllers should prefix + # the partial paths for ActiveModel objects with the namespace. + # (e.g., an Admin::PostsController would render @post using /admin/posts/_post.erb) + cattr_accessor :prefix_partial_path_with_controller_namespace + @@prefix_partial_path_with_controller_namespace = true + class_attribute :helpers class_attribute :_routes class_attribute :logger diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb index d4c652c0d1..8b53867aea 100644 --- a/actionpack/lib/action_view/renderer/partial_renderer.rb +++ b/actionpack/lib/action_view/renderer/partial_renderer.rb @@ -245,12 +245,11 @@ module ActionView # <%- end -%> # <% end %> class PartialRenderer < AbstractRenderer - PARTIAL_NAMES = Hash.new { |h,k| h[k] = {} } + PREFIXED_PARTIAL_NAMES = Hash.new { |h,k| h[k] = {} } def initialize(*) super @context_prefix = @lookup_context.prefixes.first - @partial_names = PARTIAL_NAMES[@context_prefix] end def render(context, options, block) @@ -423,7 +422,15 @@ module ActionView raise ArgumentError.new("'#{object.inspect}' is not an ActiveModel-compatible object. It must implement :to_partial_path.") end - @partial_names[path] ||= merge_prefix_into_object_path(@context_prefix, path.dup) + if @view.prefix_partial_path_with_controller_namespace + prefixed_partial_names[path] ||= merge_prefix_into_object_path(@context_prefix, path.dup) + else + path + end + end + + def prefixed_partial_names + @prefixed_partial_names ||= PREFIXED_PARTIAL_NAMES[@context_prefix] end def merge_prefix_into_object_path(prefix, object_path) |