state-machines / state_machines

Adds support for creating state machines for attributes on any Ruby class
https://github.com/state-machines/state_machines
MIT License
814 stars 91 forks source link

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

Closed obfuscoder closed 8 years ago

obfuscoder commented 8 years ago

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>
obfuscoder commented 8 years ago

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

I recommend to update the documentation.