It's annoying that if my controller happens to be namespaced, I am not allowed to render objects by using <%= render @objects %> unless I have a separate set of partials under the namespace.
<%= render @objects %>
See http://blog.obiefernandez.com/content/2012/01/rendering-collections-of-heterogeneous-objects-in-rails-32.html for more justification.
By the way, I'd like feedback on how I implemented this, and the right way to document the config setting.
@nertzy thanks for the pull request. Your implementation will accidentally break any kind of namespaced rendering, not only the partial one. I think we should instead:
Add an option to AV::Base
Check this option only here: https://github.com/nertzy/rails/blob/66d4134b9df0a5d8d7fba55f44f4307a29b48f2d/actionpack/lib/action_view/renderer/partial_renderer.rb#L430
About the docs, you can update this guide:
One difference with the ActionView::Base solution is that you won't be able to activate and de-activate the prefixing on a per-controller basis. I don't actually have a use case for this but it seemed like a nice side effect.
That said, it's definitely more of a ActionView concern and it's probably better not to mix things up too much.
@nertzy if we want to eventually set it in the controller, it could be part of the config object the controller sends to the view. but i'd worry about this when a use case actually appears :)
Test that render gets correct exact template name
OK, I've moved it to ActionView. I also made the prefix caching optional to reduce object creation when it's turned off.
Next I'll update with docs and push again.
Make controller namespace partial prefix optional
This allows you to choose to render @post using
/posts/_post.erb instead of /admin/posts/_post.erb
OK, it should be ready to go.
Will this make it into 3.2.7?
No, but you can turn it off by following Obie Fernandez's advice in this blog post: http://webcache.googleusercontent.com/search?q=cache:XNX2vHJt5rEJ:blog.obiefernandez.com/content/2012/01/rendering-collections-of-heterogeneous-objects-in-rails-32.html+http://blog.obiefernandez.com/content/2012/01/rendering-collections-of-heterogeneous-objects-in-rails-32.html&cd=1&hl=en&ct=clnk&gl=us&client=safari
(It's linked in the original pull request, but it appears his blog is down, so I found it in the Google cache.
Thanks @nertzy, I actually looked up the Google Cache of that article yesterday too, and ended up using a view resolver as described in this article linked from Obie's post, which doesn't require monkey-patching Rails.
Any reason why this was never merged into 3.2?
3-2 isn't getting new features, just bug fixes..
Thanks for the heads up @steveklabnik!