rubocop / rails-style-guide

A community-driven Ruby on Rails style guide
http://rails.rubystyle.guide
6.48k stars 1.06k forks source link

Add Action Filters Order section #353

Open ydakuka opened 11 months ago

ydakuka commented 11 months ago

It is similar to this rule, but for action filters.

ref: https://dev.to/timkrins/an-experiment-with-controller-action-callbacks-in-rails-c3p

andyw8 commented 11 months ago

I agree with the rule, but as with Callbacks Order, I think it's sufficient to give a small example (e.g. two filters) and have a link to the full list (e.g. the post referenced above).

ydakuka commented 11 months ago

have a link to the full list (e.g. the post referenced above).

I couldn't find this information, specifically the list, in the official Rails guide.

I think it's sufficient to give a small example (e.g. two filters) and have a link to the full list (e.g. the post referenced above).

Done.

pirj commented 11 months ago

We have a related guideline https://github.com/rubocop/rails-style-guide#lexically-scoped-action-filter But it doesn’t tell not to use filters in inherited classes or concerns. I believe that complex inheritance chain is sometimes a necessity.

The consequence on our case is that the order of those filters is hard to predict. And ordering just local ones would just solve part of this disorder.

ydakuka commented 11 months ago

And ordering just local ones would just solve part of this disorder.

We would have the "correct" order in all controllers. And even with inherited controllers or concerns, the code would still be easier to read. At least it definitely won’t be more difficult.