I\'m a Rails and REST newbie and I\'m trying to figure how best to expose a resource that is backed by a domain object that has a state machine (in other words is a finite a
Bit late to the party here and far from an expert as I have a similar query but...
How about making the event a resource?
So instead of...
PUT /order/53?state_event="pay" #Order.update_attributes({state_event: "pay})
You would...
POST /order/53/pay #OrderEvent.create(event_name: :pay)
POST /order/53/cancel #OrderEvent.create(event_name: :cancel)
With a pub/sub listener between Order and OrderEvent or callback that attempts to fire that event on Order and records the transition messages. It also gives you a handy audit of all state change events.
Idea stolen from Willem Bergen at Shopify
Am I missing something? Sorry, struggling to understand this myself.