开发者

State machine for Rails 3

开发者 https://www.devze.com 2023-03-23 00:33 出处:网络
My setup: Rails 3.0.9, Ruby 1.9.2 It seems like there are several state machine gems out there, acts_as_state_machine, state_machine, transitions, workflow, aasm. What\'s the one that developers u开发

My setup: Rails 3.0.9, Ruby 1.9.2

It seems like there are several state machine gems out there, acts_as_state_machine, state_machine, transitions, workflow, aasm. What's the one that developers u开发者_StackOverflow社区se the most?


According to ruby-toolbox.com the most popular is aasm.

UPD. Now the most popular is state_machine but you know where to look for it.


I know you have asked this question a long time ago, but have not yet accepted an answer.

Since Rails 3, there is a separate gem for that now. I suggest you read this tiny blog post

http://dev.netizer.pl/transitions-state-machine-for-rails-3.html

Example:

class Project < ActiveRecord::Base
  include ActiveRecord::Transitions

  # default field name is 'state', 
  # but if you want 'status'
  # you can write "state_machine :status do" instead
  state_machine do 
    state :started # first one is initial state
    state :finished
  end

end
0

精彩评论

暂无评论...
验证码 换一张
取 消