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

Controller action ordering #289

Open
mollerhoj opened this issue Sep 11, 2021 · 11 comments
Open

Controller action ordering #289

mollerhoj opened this issue Sep 11, 2021 · 11 comments

Comments

@mollerhoj
Copy link

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)

@pirj
Copy link
Member

pirj commented Sep 11, 2021

I'd love to see a confirmation that this order is followed by real-world Rails apps.

@andyw8
Copy link
Contributor

andyw8 commented Sep 11, 2021

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

@andyw8
Copy link
Contributor

andyw8 commented Sep 11, 2021

Also, as this Stack Overflow post says, some people may prefer to group the new/create and edit/update pairs together.

@mollerhoj
Copy link
Author

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).

@koic
Copy link
Member

koic commented Sep 13, 2021

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.

@pirj
Copy link
Member

pirj commented Sep 16, 2021

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.

@mollerhoj
Copy link
Author

I don't think the default order is logical - How about "Use a consistent order of resourceful actions in your controller"

@andyw8
Copy link
Contributor

andyw8 commented Sep 16, 2021

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.

@andyw8 andyw8 changed the title Controller action ording Controller action ordering Sep 17, 2021
@ydakuka
Copy link

ydakuka commented Dec 11, 2023

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

@andyw8
Copy link
Contributor

andyw8 commented Dec 11, 2023

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).

@ydakuka
Copy link

ydakuka commented Dec 12, 2023

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.

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

No branches or pull requests

5 participants