Created
February 15, 2014 22:56
-
-
Save chien/9026395 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MembershipTransitionController < ApplicationController | |
def update | |
if @membership.fire_events(params[:event_name]) | |
# handle success transition case | |
else | |
# handle failed transition | |
end | |
end | |
end | |
class Membership < ActiveRecord::Base | |
state_machine :state, initial: :applied do | |
event :approve do | |
transition :applied => :active | |
end | |
event :revoke do | |
transition :active => :inactive | |
end | |
... | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment