質問

I am using the state_machine gem. I am already using the state_machine gem successfully on one of my models, but i can't get it to work on another. In my task model, here is the state machine:

state_machine :state, :initial => :incomplete do
    event :task_finished do
        transition :incomplete => :needs_approval 
    end
end

When a new task is created, the state column is initially set to incomplete, so I know the state_machine is working somewhat. The problem is that in a rake task I call the :task_finished event but it does not work. Here is the rake task:

task :change_it => :environment do
  puts "task is working"
  @tasks = Task.already_expired
  @tasks.each do |tasko|
      tasko.task_finished
    puts "Kalabar" + tasko.inspect + "now time is:" + DateTime.now.to_s
      puts "time_frame is:" + tasko.time_frame.to_s
  end
end

How do I get it to work?

The task is getting completed because the put statements are putting to the sever, but the state is not changing from :incomplete to :needs_approval as it should. How do I fix this?

役に立ちましたか?

解決

I can't say what is wrong it is not enough information. But I can suggest you to add ! to method task_finished (so you will have tasko.task_finished!). In this way StateMachine raise an exception - and you will see what is wrong.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top