acts_as_state_machine – state is always nil
If you are using the acts_as_state_machine plugin to manage the state of your object keep this in mind:
If you are going to have an object like an order or something similar that likely has a field state_id to relate in a geographic state then you need to be sure to rename the column that acts_as_state_machine plugin uses thus:
acts_as_state_machine :initial => :new, :column => :mode
Then you can get your object's state thus:
obj.mode
If you don't follow these steps ActiveRecord will override acts_as_state_machine and try to give you the geographic state (Utah, Idaho, etc) instead of the object state (new, edit, tired, etc). (In my case the value was always nil no matter how many times I tried to obj.next! to transition the states of my object. You will cry and scream and be in a very bad mood for a long time if you forget this fact.
Here's more info on the acts_as_state_machine plugin.
More from jbasdf
- How New Carpet and Rattlesnake turned me into a Consultant or What the Hell Happened?
- First Time on the new Santa Cruz Blur XC, and Near Death Experiences
- Amazon S3, Jungle Disk and the new way to backup
- A copy of ApplicationController has been removed from the module tree but is still active! And can’t dup NilClass
- Standing on the Shoulders of Giants Adam Keys
Justin Ball is a software consultant and entrepreneur with a passion for Ruby. He evolved from a C++ and .Net monkey into a python programmer and finally found Ruby. In the rare moments when he isn't writing code, talking about code or measuring his code productivity in profanity per hour, you can find him on his bike in the mountains or on the roads surrounding Cache Valley. 









