-
-
Couldn't load subscription status.
- Fork 1.1k
Add Action Filters Order section #353
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -266,6 +266,28 @@ class UsersController < ApplicationController | |
| end | ||
| ---- | ||
|
|
||
| === Action Filters Order [[action-filters-order]] | ||
|
|
||
| Order controller filter declarations in the order in which they will be executed. | ||
| For reference, see https://dev.to/timkrins/an-experiment-with-controller-action-callbacks-in-rails-c3p[An experiment with controller action callback order in Rails]. | ||
|
|
||
| [source,ruby] | ||
| ---- | ||
| # bad | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels unnecessary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All bad examples? |
||
| class UsersController < ApplicationController | ||
| after_action :after_action_filter | ||
| prepend_around_action :prepend_around_action_filter | ||
| before_action :before_action_filter | ||
| end | ||
|
|
||
| # good | ||
| class UsersController < ApplicationController | ||
| before_action :before_action_filter | ||
| after_action :after_action_filter | ||
| prepend_around_action :prepend_around_action_filter | ||
| end | ||
| ---- | ||
|
|
||
| == Controllers: Rendering [[rendering]] | ||
|
|
||
| === Inline Rendering [[inline-rendering]] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is getting complicated with inheritance and concerns.
When it comes to a point where order matters, isn’t it a sign that a different approach is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that the action filters order will significantly impact the complexity of the code. Instead, it provides clarity in understanding the order in which the action filters are executed.
I try to avoid inheriting controllers other than inheriting from the application controller.
And as for the concerns, I haven't had any problems with them other than this one.