0

我學習Rails和嘗試使用狀態機,但我不能爲狀態初始化值variable..can誰能幫我state_machine在軌道4,5不正確的初始化狀態列值

class Primer < ActiveRecord::Base 
    extend StateMachine::MacroMethods 

    state_machine :initial => :data do 
     event :ignite do 
     transition :parked => :idling 
     end 
    end 
end 

數據庫架構

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 

嘗試

軌道ç

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 

回答