I am learning Rails and try to use state machine but i am not able to initialize value for state variable..can anyone help me
class Primer < ActiveRecord::Base
extend StateMachine::MacroMethods
state_machine :initial => :data do
event :ignite do
transition :parked => :idling
end
end
end
database schema
class CreatePrimers < ActiveRecord::Migration
def change
create_table :primers do |t|
t.string :name
t.string :state
t.string :desc
t.timestamps null: false
end
end
end
try with
rails c
a = Primer.new
=> #<Primer id: nil, name: nil, state: nil, desc: nil, created_at: nil, updated_at: nil>
2.2.0 :002 > a.state
=> nil
Seems like a known issue https://github.com/pluginaweek/state_machine/issues/334
And new gem suggested is https://github.com/state-machines/state_machines-activerecord