-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add config option to turn off prefixing partial path with controller namespace #5625
Add config option to turn off prefixing partial path with controller namespace #5625
Conversation
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:
About the docs, you can update this guide: https://github.com/rails/rails/blob/master/guides/source/configuring.textile |
Thanks! 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. |
cc @Peeja |
@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 :) |
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. |
config.action_view.prefix_partial_path_with_controller_namespace This allows you to choose to render @post using /posts/_post.erb instead of /admin/posts/_post.erb inside Admin::PostsController.
OK, it should be ready to go. |
…ler_namespace Add config option to turn off prefixing partial path with controller namespace
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! |
Closes [rails#50844][] Motivation / Background --- A controller declared in the top-level module can render a top-level Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`). A controller scoped within a module can render an Active Model instance whose partial is similarly scoped within view directory (like `scoped/articles/_article.html.erb`). A controller scoped within a module cannot render an Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`), despite the absence of a similarly scoped partial. This is intended behavior that's powered by [`config.action_view.prefix_partial_path_with_controller_namespace = true`][prefix_partial_path_with_controller_namespace] (`true` by default). This change was introduced in March of 2012 as part of [rails#5625][]. Detail --- As a consumer of Action View, my intuition is that the lookup would fallback, in the same way that a controller that inherits from `ApplicationController` could define its own view, then rely on fallback to render an `app/views/application` partial. This commit modifies the behavior to gracefully fall back to the root-level view partial. Checklist --- Before submitting the PR make sure the following are checked: * [x] This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs. * [x] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: `[Fix #issue-number]` * [x] Tests are added or updated if you fix a bug or add a feature. * [x] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included. [#59844]: rails#50844 [prefix_partial_path_with_controller_namespace]: https://guides.rubyonrails.org/configuring.html#config-action-view-prefix-partial-path-with-controller-namespace [rails#5625]: rails#5625
Closes [rails#50844][] Motivation / Background --- A controller declared in the top-level module can render a top-level Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`). A controller scoped within a module can render an Active Model instance whose partial is similarly scoped within view directory (like `scoped/articles/_article.html.erb`). A controller scoped within a module cannot render an Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`), despite the absence of a similarly scoped partial. This is intended behavior that's powered by [`config.action_view.prefix_partial_path_with_controller_namespace = true`][prefix_partial_path_with_controller_namespace] (`true` by default). This change was introduced in March of 2012 as part of [rails#5625][]. Detail --- As a consumer of Action View, my intuition is that the lookup would fallback, in the same way that a controller that inherits from `ApplicationController` could define its own view, then rely on fallback to render an `app/views/application` partial. This commit modifies the behavior to gracefully fall back to the root-level view partial. Checklist --- Before submitting the PR make sure the following are checked: * [x] This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs. * [x] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: `[Fix #issue-number]` * [x] Tests are added or updated if you fix a bug or add a feature. * [x] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included. [#59844]: rails#50844 [prefix_partial_path_with_controller_namespace]: https://guides.rubyonrails.org/configuring.html#config-action-view-prefix-partial-path-with-controller-namespace [rails#5625]: rails#5625
Closes [rails#50844][] Motivation / Background --- A controller declared in the top-level module can render a top-level Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`). A controller scoped within a module can render an Active Model instance whose partial is similarly scoped within view directory (like `scoped/articles/_article.html.erb`). A controller scoped within a module cannot render an Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`), despite the absence of a similarly scoped partial. This is intended behavior that's powered by [`config.action_view.prefix_partial_path_with_controller_namespace = true`][prefix_partial_path_with_controller_namespace] (`true` by default). This change was introduced in March of 2012 as part of [rails#5625][]. Detail --- As a consumer of Action View, my intuition is that the lookup would fallback, in the same way that a controller that inherits from `ApplicationController` could define its own view, then rely on fallback to render an `app/views/application` partial. This commit modifies the behavior to gracefully fall back to the root-level view partial. Checklist --- Before submitting the PR make sure the following are checked: * [x] This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs. * [x] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: `[Fix #issue-number]` * [x] Tests are added or updated if you fix a bug or add a feature. * [x] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included. [#59844]: rails#50844 [prefix_partial_path_with_controller_namespace]: https://guides.rubyonrails.org/configuring.html#config-action-view-prefix-partial-path-with-controller-namespace [rails#5625]: rails#5625
Closes [rails#50844][] Motivation / Background --- A controller declared in the top-level module can render a top-level Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`). A controller scoped within a module can render an Active Model instance whose partial is similarly scoped within view directory (like `scoped/articles/_article.html.erb`). A controller scoped within a module cannot render an Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`), despite the absence of a similarly scoped partial. This is intended behavior that's powered by [`config.action_view.prefix_partial_path_with_controller_namespace = true`][prefix_partial_path_with_controller_namespace] (`true` by default). This change was introduced in March of 2012 as part of [rails#5625][]. Detail --- As a consumer of Action View, my intuition is that the lookup would fallback, in the same way that a controller that inherits from `ApplicationController` could define its own view, then rely on fallback to render an `app/views/application` partial. This commit modifies the behavior to gracefully fall back to the root-level view partial. Checklist --- Before submitting the PR make sure the following are checked: * [x] This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs. * [x] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: `[Fix #issue-number]` * [x] Tests are added or updated if you fix a bug or add a feature. * [x] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included. [#59844]: rails#50844 [prefix_partial_path_with_controller_namespace]: https://guides.rubyonrails.org/configuring.html#config-action-view-prefix-partial-path-with-controller-namespace [rails#5625]: rails#5625
Closes [rails#50844][] Motivation / Background --- A controller declared in the top-level module can render a top-level Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`). A controller scoped within a module can render an Active Model instance whose partial is similarly scoped within view directory (like `scoped/articles/_article.html.erb`). A controller scoped within a module cannot render an Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`), despite the absence of a similarly scoped partial. This is intended behavior that's powered by [`config.action_view.prefix_partial_path_with_controller_namespace = true`][prefix_partial_path_with_controller_namespace] (`true` by default). This change was introduced in March of 2012 as part of [rails#5625][]. Detail --- As a consumer of Action View, my intuition is that the lookup would fallback, in the same way that a controller that inherits from `ApplicationController` could define its own view, then rely on fallback to render an `app/views/application` partial. This commit modifies the behavior to gracefully fall back to the root-level view partial. Checklist --- Before submitting the PR make sure the following are checked: * [x] This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs. * [x] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: `[Fix #issue-number]` * [x] Tests are added or updated if you fix a bug or add a feature. * [x] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included. [#59844]: rails#50844 [prefix_partial_path_with_controller_namespace]: https://guides.rubyonrails.org/configuring.html#config-action-view-prefix-partial-path-with-controller-namespace [rails#5625]: rails#5625
Closes [rails#50844][] Motivation / Background --- A controller declared in the top-level module can render a top-level Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`). A controller scoped within a module can render an Active Model instance whose partial is similarly scoped within view directory (like `scoped/articles/_article.html.erb`). A controller scoped within a module cannot render an Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`), despite the absence of a similarly scoped partial. This is intended behavior that's powered by [`config.action_view.prefix_partial_path_with_controller_namespace = true`][prefix_partial_path_with_controller_namespace] (`true` by default). This change was introduced in March of 2012 as part of [rails#5625][]. Detail --- As a consumer of Action View, my intuition is that the lookup would fallback, in the same way that a controller that inherits from `ApplicationController` could define its own view, then rely on fallback to render an `app/views/application` partial. This commit modifies the behavior to gracefully fall back to the root-level view partial. Checklist --- Before submitting the PR make sure the following are checked: * [x] This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs. * [x] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: `[Fix #issue-number]` * [x] Tests are added or updated if you fix a bug or add a feature. * [x] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included. [#59844]: rails#50844 [prefix_partial_path_with_controller_namespace]: https://guides.rubyonrails.org/configuring.html#config-action-view-prefix-partial-path-with-controller-namespace [rails#5625]: rails#5625
Closes [rails#50844][] Motivation / Background --- A controller declared in the top-level module can render a top-level Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`). A controller scoped within a module can render an Active Model instance whose partial is similarly scoped within view directory (like `scoped/articles/_article.html.erb`). A controller scoped within a module cannot render an Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`), despite the absence of a similarly scoped partial. This is intended behavior that's powered by [`config.action_view.prefix_partial_path_with_controller_namespace = true`][prefix_partial_path_with_controller_namespace] (`true` by default). This change was introduced in March of 2012 as part of [rails#5625][]. Detail --- As a consumer of Action View, my intuition is that the lookup would fallback, in the same way that a controller that inherits from `ApplicationController` could define its own view, then rely on fallback to render an `app/views/application` partial. This commit modifies the behavior to gracefully fall back to the root-level view partial. Checklist --- Before submitting the PR make sure the following are checked: * [x] This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs. * [x] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: `[Fix #issue-number]` * [x] Tests are added or updated if you fix a bug or add a feature. * [x] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included. [#59844]: rails#50844 [prefix_partial_path_with_controller_namespace]: https://guides.rubyonrails.org/configuring.html#config-action-view-prefix-partial-path-with-controller-namespace [rails#5625]: rails#5625
Closes [rails#50844][] Motivation / Background --- A controller declared in the top-level module can render a top-level Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`). A controller scoped within a module can render an Active Model instance whose partial is similarly scoped within view directory (like `scoped/articles/_article.html.erb`). A controller scoped within a module cannot render an Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`), despite the absence of a similarly scoped partial. This is intended behavior that's powered by [`config.action_view.prefix_partial_path_with_controller_namespace = true`][prefix_partial_path_with_controller_namespace] (`true` by default). This change was introduced in March of 2012 as part of [rails#5625][]. Detail --- As a consumer of Action View, my intuition is that the lookup would fallback, in the same way that a controller that inherits from `ApplicationController` could define its own view, then rely on fallback to render an `app/views/application` partial. This commit modifies the behavior to gracefully fall back to the root-level view partial. Checklist --- Before submitting the PR make sure the following are checked: * [x] This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs. * [x] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: `[Fix #issue-number]` * [x] Tests are added or updated if you fix a bug or add a feature. * [x] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included. [#59844]: rails#50844 [prefix_partial_path_with_controller_namespace]: https://guides.rubyonrails.org/configuring.html#config-action-view-prefix-partial-path-with-controller-namespace [rails#5625]: rails#5625
Closes [rails#50844][] Motivation / Background --- A controller declared in the top-level module can render a top-level Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`). A controller scoped within a module can render an Active Model instance whose partial is similarly scoped within view directory (like `scoped/articles/_article.html.erb`). A controller scoped within a module cannot render an Active Model instance whose partial is declared in the root view directory (like `articles/_article.html.erb`), despite the absence of a similarly scoped partial. This is intended behavior that's powered by [`config.action_view.prefix_partial_path_with_controller_namespace = true`][prefix_partial_path_with_controller_namespace] (`true` by default). This change was introduced in March of 2012 as part of [rails#5625][]. Detail --- As a consumer of Action View, my intuition is that the lookup would fallback, in the same way that a controller that inherits from `ApplicationController` could define its own view, then rely on fallback to render an `app/views/application` partial. This commit modifies the behavior to gracefully fall back to the root-level view partial. Checklist --- Before submitting the PR make sure the following are checked: * [x] This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs. * [x] Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: `[Fix #issue-number]` * [x] Tests are added or updated if you fix a bug or add a feature. * [x] CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included. [#59844]: rails#50844 [prefix_partial_path_with_controller_namespace]: https://guides.rubyonrails.org/configuring.html#config-action-view-prefix-partial-path-with-controller-namespace [rails#5625]: rails#5625
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.See http://blog.obiefernandez.com/content/2012/01/rendering-collections-of-heterogeneous-objects-in-rails-32.html for more justification.
cc @josevalim