0
我對'工作流'gem有點麻煩,即轉換不起作用。rails工作流gem方法缺少錯誤狀態機
我想要做的是非常基本的,我有一個用戶之間的消息「讀取/未讀」狀態,當用戶轉到特定消息的「顯示」頁面時,會觸發該轉換。不過,我似乎無法獲得到工作的過渡,甚至在控制檯:
\\ 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甚至ANYTHING試圖尋找在:/home/Ryan/.bundle/ruby/1.8/gems/workflow-0.7.0/lib/workflow .rb但我看不到任何理由,這是行不通的。這是一個非常簡單的問題,我扼殺了我的大腦,找出了錯誤。
感謝您的幫助
感謝。我最終只使用了acts_as_state_machine,因爲顯然我的需求非常簡單。但是,是的,這是我的問題。 – goddamnyouryan 2011-01-27 04:03:04