Open mollerhoj opened 3 years ago
I'd love to see a confirmation that this order is followed by real-world Rails apps.
Just for the sake of discussion, another possible way of ordering could be to follow CRUD, e.g.:
new create index show edit update destroy
Also, as this Stack Overflow post says, some people may prefer to group the new/create
and edit/update
pairs together.
I honestly like the CRUD order better, but consistency is my no. 1 priority. (I really just want to see a rubocop, but they refered me to this guide).
The default order of controller actions in rails scaffolds are:
I agree with the default order if this rule is needed. I think it's better to follow the scaffold order. This is the official starting point of Rails.
What do you think of a soft wording for the guideline? e.g.
Use the default order of resourceful actions in your controller. Feel free to intermingle them with additional non-resourceful actions deliberately.
I don't think the default order is logical - How about "Use a consistent order of resourceful actions in your controller"
Feel free to intermingle them with additional non-resourceful actions deliberately.
This feels like it encourages non-resourceful actions, rather than just permitting them. How about:
Use a consistent order for the resourceful actions in your controller. Non-resourceful actions can be interspersed where needed.
The default order of controller actions in rails scaffolds are: index show new edit create update destroy
Yes, and the order is grouped by HTTP method.
However, the order displayed at http://localhost:3000/rails/info/routes is different:
index create new edit show update destroy
Since it's proving difficult to reach an agreed ordering, perhaps the guideline should just be to use a consistent ordering.
A cop can then be written to allow the developer to configure their preferred order (without any default).
A cop can then be written to allow the developer to configure their preferred order (without any default).
The cop has been already written.
I believe the issue remains open due to this comment.
The default order of controller actions in rails scaffolds are:
index show new edit create update destroy
I often see controllers where this order is not followed. For consistency's sake, I'd like to have a rubocop to enforce this ordering of the public methods in my controllers.
As a side note: We strive towards never using any other actions in our controllers (https://www.youtube.com/watch?v=HctYHe-YjnE)