使用state_machines gem的bug - 状态变量返回nil

时间:2015-08-06 06:20:44

标签: ruby-on-rails ruby ruby-on-rails-4 state-machine

我在做什么时

d = Design.find_by(id: 1111, state: 'in_stock')

我得到了一个完美的结果,这意味着数据库记录的状态值保持/存储为in_stock。

但是当我做的时候

d.state => nil

我使用state_machines gem来实现状态机

class Design < ActiveRecord::Base
 state_machine initial: :sold_out do

  event :stock_added do
   transition [:processing, :sold_out, :seller_out_of_stock, :blocked,
    :banned, :review, :on_hold, :reject] => :in_stock
  end

  event :stock_removed do
   transition [:blocked, :in_stock, :sold_out] => :seller_out_of_stock
  end

  before_transition to: :in_stock do |design|
   design.last_in_stock = Time.now
   if design.designer.vacation?
    design.designer_vacation
    false
   end
  end
 end
end

0 个答案:

没有答案