美文网首页
aasm 交换机 订单状态交换功能

aasm 交换机 订单状态交换功能

作者: biubiudog | 来源:发表于2019-06-06 14:22 被阅读0次

    使用:

    1. 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: :事件

    相关文章

      网友评论

          本文标题:aasm 交换机 订单状态交换功能

          本文链接:https://www.haomeiwen.com/subject/sabefqtx.html