RailsConf 2017: In Relentless Pursuit of REST by Derek Prior
REST help rails growing
More small things (small models, controllers, services, views...)
[Anti-pattern] Custom actions
- When having
users#update_password) = Missing resource -> Resource is
- Controllers do not need to map to ActiveRecord objects
- When having
[Anti-pattern] Complex actions
- Make boring code
- Less before_actions
- Use service object, query objects, objects to extract complexity
- Be boring (boring controller, boring model, ...)
[Anti-pattern] Ambiguous language
- "process"? What does it mean?
- Don't be scared about duplicate code. "duplication is far cheaper than the wrong abstraction" (cf Sandi Metz)
- This change
Shipments#createcreate a "breathing room".
[Anti-pattern] State Machines
- Code spaghetti.
- State machines are magnetic : they attract more states, transitions, events, callbacks and they accumulate callback logic where our bugs hide
- State machines are not easy to clean
- What if
- Move to REST with a object/service object for the step of state machine
- Any move to tiner ruby object will be a win
Outside in (https://youtu.be/HctYHe-YjnE?t=1696)
- We changing the language of the applcation from "What this application store, and how this is stored" to "What it this application does" (at a higher level)
- In most case what's keeping any app from being a CRUD app is a lack of imagination : You have'nt gone back to rethink the problem from the outside to identify the resource you're talking about.
- Be boring. Be RESTful.