geekq/workflow — Issue #41: Correct way to check object.halted? from controller?
Author: johnrees
Created: 2011-12-17 10:58:30+00:00
State: open

I have a conditional halt in my model

def approve
halt! 'The invoice must be linked to a project' unless self.project
end

And in the controller I want to write something like below, so that it doesn't show the standard Workflow::TransitionHalted error page. (It doesn't work because `@received_invoice.approve!` is always called) I know about the `halted?` method but was wondering what the recommended way was to implement this in the controller.

def approve
@received_invoice = ReceivedInvoice.find(params[:id])
if @received_invoice.approve!
redirect_to received_invoice_url(@received_invoice), notice: 'Invoice approved'
else
redirect_to received_invoice_url(@received_invoice), notice: @received_invoice.halted_because
end
end