Skip to content

Instantly share code, notes, and snippets.

@gerardosandoval
Created May 22, 2018 23:34
Show Gist options
  • Save gerardosandoval/1e1de0fdee7580544b5e65eb45424edc to your computer and use it in GitHub Desktop.
Save gerardosandoval/1e1de0fdee7580544b5e65eb45424edc to your computer and use it in GitHub Desktop.
Refactoring checklist
Taken from expertise.jetruby.com
Controller checklist
- the controller doesn’t have any business logic
- the controller doesn’t have any controlling constructions (except from “if success? then respond_with_success else respond_with_error end”)
- the controller doesn’t know anything about how the data is arranged (to make the user active, you need to call “current_user.activate!”, not current_user.update(status: ‘active’))
- there’s no duplicated logic for new, create and edit, update actions. The records should be in “before_action”
- in the “action” methods there is no validation of whether those methods can be executed (put all of that in “before_filter”).
Views checklist
- repeating pieces of code are moved to partials
- there are no logic views; it should be moved to helper methods
- instance variables of the controller should be in the current view, which is transferred to all partials and helpers through parameters (sometimes you can use “helper_method” of the controller instead of instance variables)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment