Skip to content

Instantly share code, notes, and snippets.

  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save padi/f47f838da7a1502d244d933487f23d3e to your computer and use it in GitHub Desktop.
"In Relentless Pursuit of Rest" from Derek Prior

RailsConf 2017: In Relentless Pursuit of REST by Derek Prior

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 is password (password#edit, password#update)
    • Controllers do not need to map to ActiveRecord objects
  • [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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment