我对'workflow'宝石有点麻烦,即转换不起作用。
我想要做的是非常基本的,我对用户之间的消息有“读/未读”状态,当用户进入该特定消息的“显示”页面时会触发转换。但是,即使在控制台中,我似乎也无法实现过渡:
\\ message.rb
class Message < ActiveRecord::Base
include Workflow
workflow do
state :unread do
event :view, :transitions_to => :read
end
state :read
end
end
在控制台中,当我尝试进行此转换时,我使用以下代码并获得以下输出:
>> message = Message.new
=> #<Message id: nil, user_id: nil, message: nil, created_at: nil, u
pdated_at: nil>
>> message.current_state
=> #<Workflow::State:0x7ed4febc @name=:unread, @events={:view=>#<Workflow:
:Event:0x7ed4fd90 @action=nil, @name=:view, @transitions_to=:read, @meta={}
>}, @meta={}>
>> message.unread?
=> true
>> message.view!
NoMethodError: undefined method `workflow_state=' for #<Message:0x7ecfd5a4>
from /home/Ryan/.bundle/ruby/1.8/gems/activerecord-2.3.8/lib/active_reco
rd/attribute_methods.rb:259:in `method_missing'
from /home/Ryan/.bundle/ruby/1.8/gems/activerecord-2.3.8/lib/active_reco
rd/base.rb:2656:in `send'
from /home/Ryan/.bundle/ruby/1.8/gems/activerecord-2.3.8/lib/active_reco
rd/base.rb:2656:in `update_attribute'
from /home/Ryan/.bundle/ruby/1.8/gems/workflow-0.7.0/lib/workflow.rb:272
:in `persist_workflow_state'
from /home/Ryan/.bundle/ruby/1.8/gems/workflow-0.7.0/lib/workflow.rb:211
:in `transition'
from /home/Ryan/.bundle/ruby/1.8/gems/workflow-0.7.0/lib/workflow.rb:165
:in `process_event!'
from /home/Ryan/.bundle/ruby/1.8/gems/workflow-0.7.0/lib/workflow.rb:124
:in `view!'
from (irb):25
我找不到任何关于这里发生了什么,从googleing甚至尝试查看:/home/Ryan/.bundle/ruby/1.8/gems/workflow-0.7.0/lib/workflow.rb但是我看不出有什么理由不行。这是一个非常简单的问题,我已经弄乱了我的大脑,弄清楚出了什么问题。
感谢您的帮助
答案 0 :(得分:1)
您是否使用workflow_state
作为存储状态的列名?
如果没有,则将workflow_column :your_column_name
放入模型代码中。
您可以在控制台中输入以检查设置:
Message.workflow_column