For the longest time PartialRenderer#partial_path has prefixed the prefix of the current controller when it is nested in a module. This hasn''t been a problem (because nesting controllers wasn''t that common) but with 3.1 striving for better engine support, this problem is now larger because all of your controllers for an engine will be nested and it makes doing <%= render @thing %> in your code (and anybody else''s) extremely tedious and impossible without specifying the :partial to use. https://github.com/rails/rails/blob/master/actionpack/lib/action_view/renderer/partial_renderer.rb#L150-159 Normally this function grabs the partial to use with model_name.partial_path which is great for default views (things/ _thing.html.erb) but as soon as you call it from a controller that is nested it ends up giving you a path like controller_namespace/things/ _thing.html.erb. I can see the advantage of that (if you want different partial for @thing in your admin namespace) but I think the disadvantage of being unable to reuse your partials is too big (especially with other code using your engine). module Foo class Engine < Rails::Engine; isolate_namespace Foo; end class ApplicationController < ActionController::Base; end class Thing < ActiveRecord::Base; end end Foo::Thing.connection.create_table(:foo_things) Foo::ApplicationController.new.view_context._partial_renderer.send(:partial_path, Foo::Thing.new) => "foo/foo/things/thing" I believe the solution should be to change the default behaviour or at least provide an option to stop rails from prefixing the partial_path. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Antonio Tapiador del Dujo
2011-Apr-07 07:33 UTC
Re: Time to fix PartialRenderer#partial_path
El Miércoles, 6 de Abril de 2011 17:07:48 Samuel Kadolph escribió:> For the longest time PartialRenderer#partial_path has prefixed the > prefix of the current controller when it is nested in a module. This > hasn''t been a problem (because nesting controllers wasn''t that common) > but with 3.1 striving for better engine support, this problem is now > larger because all of your controllers for an engine will be nested > and it makes doing <%= render @thing %> in your code (and anybody > else''s) extremely tedious and impossible without specifying > the :partial to use. > > https://github.com/rails/rails/blob/master/actionpack/lib/action_view/rende > rer/partial_renderer.rb#L150-159 Normally this function grabs the partial > to use with > model_name.partial_path which is great for default views (things/ > _thing.html.erb) but as soon as you call it from a controller that is > nested it ends up giving you a path like controller_namespace/things/ > _thing.html.erb. I can see the advantage of that (if you want > different partial for @thing in your admin namespace) but I think the > disadvantage of being unable to reuse your partials is too big > (especially with other code using your engine). > > module Foo > class Engine < Rails::Engine; isolate_namespace Foo; end > class ApplicationController < ActionController::Base; end > class Thing < ActiveRecord::Base; end > end > Foo::Thing.connection.create_table(:foo_things) > Foo::ApplicationController.new.view_context._partial_renderer.send(:partial > _path, Foo::Thing.new) > => "foo/foo/things/thing" > > I believe the solution should be to change the default behaviour or at > least provide an option to stop rails from prefixing the partial_path.I agree. We recently went through this and it was a bit weird. We were calling <%= render @object %> inside a Foo::BarsController and Rails looked for ''foo/objects/_object'', that was not our intention. We were indeed looking for an option like that. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.