Closed benzelano closed 13 years ago
(from [27361129a8607b5922995e656701428ed617ed18]) Fix events not failing with useful errors when an object’s state is invalid [#25 state:resolved] http://github.com/pluginaweek/state_machine/commit/27361129a8607b5922995e656701428ed617ed18
Thanks for the report. As you might notice from the above change, this problem occurs because the state of the record (nil in your case) is unknown to the state machine. In order for the state machine to work on an existing record, you have to make sure that the existing records are all in valid states. If nil is valid state in this case, then you can define it like so:
class User
state_machine do
...
state nil
end
end
This will define a nil state and will therefore not error out when trying to transition on an object with that state.
Hope this helps!
Nicolas Blanco opened this issue
state_machine is a great plugin but I’ve found a problem.
When you add a state_machine to an existing ActiveRecord model and load an existing model, the state of the model is therefore nil, state_machine raises an exception when you call an event.
@@@
original LH ticket
This ticket has 0 attachment(s).