Slides : https://speakerdeck.com/derekprior/in-relentless-pursuit-of-rest Talk : https://www.youtube.com/watch?v=HctYHe-YjnE
-
REST help rails growing
-
More small things (small models, controllers, services, views...)
-
[Anti-pattern] Custom actions
- When having
noun#verb_noun
(users#edit_password
,users#update_password
) = Missing resource -> Resource ispassword
(password#edit
,password#update
) - 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?
Order#process
->Shipments#create
- Don't be scared about duplicate code. "duplication is far cheaper than the wrong abstraction" (cf Sandi Metz)
- This change
Order#process
->Shipments#create
create 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
update
didn't exist? - 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.