使用:
gem 'aasm'
2.设置一个初始状态
class Customer < ActiveRecord::Base
include AASM
aasm do
state :published, initial => true
state :checked_success
state :checked_faild
end
end
3.状态转换
初始状态为published
(未审核),审核通过,则为checked
,审核未通过,则为denied
。
class Customer < ActiveRecord::Base
include AASM
aasm do
state :published, initial => true
state :checked_success
state :checked_faild
state :deleted
#正在审核
event :on_checked do
translation :from => :published, :to => :on_checking
end
#审核通过
event :checked_succeed do
translation :from => :on_checking, :to => :finished
end
#删除该记录
event :deleted do
translation :from => [:checked, :finished], :to => :sleeping
end
end
end
触发切换事件执行的条件 after_commit: :事件
网友评论