# Acts\_as\_state\_machine

**URL:** <https://www.ruby-forum.com/t/acts-as-state-machine/133633>\
**Category:** Rails\
**Created:** [April 2, 2008, 5:27am UTC](https://www.ruby-forum.com/t/acts-as-state-machine/133633 "2008-04-02T05:27:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![srinivasraopala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@srinivasraopala](https://www.ruby-forum.com/u/srinivasraopala)\
**Post date:** [April 2, 2008, 5:27am UTC](https://www.ruby-forum.com/t/acts-as-state-machine/133633/1 "2008-04-02T05:27:18Z")

</div>

Hi,

I want to use the acts\_as\_state\_machine for work flow.  
Please let me know how to use this.

Can you please give one example.

Thank you,  
srinivasrao.pala

---

<div class="post-metadata">

**Author:** ![srinivasraopala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@srinivasraopala](https://www.ruby-forum.com/u/srinivasraopala)\
**Post date:** [April 2, 2008, 4:07pm UTC](https://www.ruby-forum.com/t/acts-as-state-machine/133633/2 "2008-04-02T16:07:47Z")

</div>

Check the example here:  
[http://agilewebdevelopment.com/plugins/acts\_as\_state\_machine](http://agilewebdevelopment.com/plugins/acts_as_state_machine)

It’s fairly straightforward. First, you declare the acceptable  
‘states’ for the object. aasm assumes that you will have an initial  
state called ‘initial’ and that the state is stored in a column named  
‘state’ but you can override both of those conventions.

Next you declare the permissible ‘transitions’ that change the object  
from one state to another. If the transition from state X=\>Y should  
occur only if certain other conditions are met then you can add  
a :guard=\>xxx to the transition (xxx= a Proc or a method name).  
Similarly you can specify :exit and :enter methods that should be  
executed when the transition is followed.

Finally, you use the transitions in your business logic. Referring to  
the link posted above, you would trigger the :accept transition on and  
instance of the Nonprofit with some code like this:

@nonprofit = Nonprofit.find params[:id]  
@nonprofit.accept! #Note that the transition has given you a !-method  
with the same name

On Apr 1, 11:27 pm, Srinu P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
