Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
"In Relentless Pursuit of Rest" from Derek Prior

RailsConf 2017: In Relentless Pursuit of REST by Derek Prior

Slides : Talk :

  • 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 (

    • 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