state-machines/state_machines

Implicit event transitions not possible - NoMethodError: undefined method `status_event='

obfuscoder opened this issue · 1 comments

I have some ActveRecord based model like this:

class MyModel < ActiveRecord::Base
  state_machine :status, initial: :initial do
    event :order_purchased do
      transition [:initial, :ordered] => :ordered
    end

    state :initial
    state :ordered
  end
end

I want to implicitly trigger the order_purchased event and update other attributes at the same time. When using state_machine this worked like so:

my_model.update_attributes status_event: :order_purchased, other_attribute: 'value'

With state_machines, however, I get an error:

ActiveRecord::UnknownAttributeError: unknown attribute: status_event

Also trying something like given in the README of state_machines (copied from state_machine) like the following:

my_model.status_event = 'order_purchased'

Does yield

NoMethodError: undefined method `status_event=' for #<MyModel:0x4c7a0338>

Apparently when referencing the gem 'state_machines-activerecord' instead of 'state_machines', this works as expected.

I recommend to update the documentation.