Skip to content
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

Merged

Conversation

nertzy
Copy link
Contributor

@nertzy nertzy commented Mar 28, 2012

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

@nertzy
Copy link
Contributor Author

nertzy commented Mar 28, 2012

By the way, I'd like feedback on how I implemented this, and the right way to document the config setting.

@josevalim
Copy link
Contributor

@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:

  1. Add an option to AV::Base

  2. 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:

https://github.com/rails/rails/blob/master/guides/source/configuring.textile

@nertzy
Copy link
Contributor Author

nertzy commented Mar 28, 2012

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.

@nertzy
Copy link
Contributor Author

nertzy commented Mar 28, 2012

cc @Peeja

@josevalim
Copy link
Contributor

@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 :)

@nertzy
Copy link
Contributor Author

nertzy commented Mar 29, 2012

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.
@nertzy
Copy link
Contributor Author

nertzy commented Mar 29, 2012

OK, it should be ready to go.

josevalim added a commit that referenced this pull request Mar 29, 2012
…ler_namespace

Add config option to turn off prefixing partial path with controller namespace
@josevalim josevalim merged commit e51322a into rails:master Mar 29, 2012
@toupeira
Copy link

Will this make it into 3.2.7?

@nertzy
Copy link
Contributor Author

nertzy commented Jul 12, 2012

@toupeira
Copy link

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.

@oriolgual
Copy link
Contributor

Any reason why this was never merged into 3.2?

@steveklabnik
Copy link
Member

3-2 isn't getting new features, just bug fixes..

@oriolgual
Copy link
Contributor

Thanks for the heads up @steveklabnik!

seanpdoyle added a commit to seanpdoyle/rails that referenced this pull request Jan 23, 2024
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
seanpdoyle added a commit to seanpdoyle/rails that referenced this pull request Mar 2, 2024
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
seanpdoyle added a commit to seanpdoyle/rails that referenced this pull request Apr 18, 2024
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
seanpdoyle added a commit to seanpdoyle/rails that referenced this pull request Apr 18, 2024
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
seanpdoyle added a commit to seanpdoyle/rails that referenced this pull request Apr 19, 2024
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
seanpdoyle added a commit to seanpdoyle/rails that referenced this pull request Apr 20, 2024
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
seanpdoyle added a commit to seanpdoyle/rails that referenced this pull request Apr 20, 2024
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
seanpdoyle added a commit to seanpdoyle/rails that referenced this pull request May 15, 2024
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
seanpdoyle added a commit to seanpdoyle/rails that referenced this pull request May 16, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants