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 Action Filters Order section #353

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

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?

Copy link
Author

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.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels unnecessary

Copy link
Author

Choose a reason for hiding this comment

The 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]]
Expand Down