0

我正在学习 Rails 并尝试使用状态机,但我无法初始化状态变量的值..谁能帮助我

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

尝试

导轨 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
4

1 回答 1

4

似乎是一个已知问题https://github.com/pluginaweek/state_machine/issues/334

建议的新宝石是https://github.com/state-machines/state_machines-activerecord

于 2015-10-27T14:22:26.187 回答