Skip to content

Instantly share code, notes, and snippets.

@chien
Created February 15, 2014 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chien/9026395 to your computer and use it in GitHub Desktop.
Save chien/9026395 to your computer and use it in GitHub Desktop.
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