geekq / workflow

Ruby finite-state-machine-inspired API for modeling workflow
MIT License
1.75k stars 207 forks source link

Is it possible to trigger an event from a Rails controller #update without custom controller code? #173

Closed duffyjp closed 2 years ago

duffyjp commented 8 years ago

If I pass {workflow_state: :archived} where 'archived' is a state, the normal controller update accepts this and saves the workflow_state and everything is fine. What I'd like to do however is pass :archive which is the event that transitions to :archived. When I try, my workflow_state reverts to :new, presumably because :archive is not a state, but an event.

I don't really want to check for every possible event in the controller and trigger the event, it seems hacky. Passing the state I'd have transitioned to does work, but skips any event handler I may want to define.

What feels natural is to use PATCH, send the object ID, and workflow_event to the controller and have all the normal hooks do their thing, like I had called my_model.archive! myself.

<% [:archive, :promote].each do |action| %>
  <%= link_to action.to_s, item_path(@item, item: {workflow_event: action}), method: :patch %>
<% end %>
franzliedke commented 6 years ago

I am also interested in this use case.

What I don't want: