Skip to content

Commit 810d814

Browse files
authored
Update controller organization rules (#113)
1 parent f8b2ba4 commit 810d814

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

general/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Style and best practices that apply to all languages and frameworks.
4545

4646
## Organization
4747

48-
- Define methods alphabetically.
48+
- Define methods alphabetically. (See Rails guide for more details about an exception in controllers.)
4949
- Define class methods before instance methods.
5050
- Always define the `initialize` method of a class at the top of instance method
5151
definitions.

rails/.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Rails/ActionFilter:
2020
Description: "Enforces consistent use of action filter methods."
2121
Enabled: false
2222

23+
Rails/ActionOrder:
24+
Description: "Enforces the order of CRUD controller methods."
25+
Enabled: true
26+
2327
Rails/Date:
2428
Description: >-
2529
Checks the correct usage of date aware methods,

rails/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ A guide for building great Rails apps.
1212
attribute name.
1313
- Order ActiveRecord validations alphabetically by attribute name.
1414
- Order ActiveRecord associations above ActiveRecord validations.
15-
- Order controller contents: filters, public methods, private methods.
15+
- Order controller contents: standard actions, custom actions, filter methods, private methods.
16+
- Standard methods should be organized using the official Rails order (see `Rails/ActionOrder` cop)
17+
- All other methods should be organized in their respective sections alphabetically
1618
- Order i18n translations alphabetically by key name.
1719
- Order model contents: constants, macros, public methods, private methods.
1820
- Use link_to for GET requests, and button_to for other HTTP verbs.

0 commit comments

Comments
 (0)