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 %>
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.