look at the following model class using asm:
class User < ActiveRecord::Base
acts_as_state_machine :initial => :pending
state :pending
state :enabled
state :disabled
event :enable do
transitions :from => :pending, :to => :enabled
transitions :from => :disabled, :to => :enabled
end
event :disable do
transitions :from => :pending, :to => :disabled
transitions :from => :enabled, :to => :disabled
end
endHere, normal user registration will cause initial state of
user object to be a "pending" state; but when admin creates
an user it should be "enabled", but asm will force the model
to keep the state to be "pending".
We can achieve required solution by doing the following:--
def create
User.write_inheritable_attribute :initial_state, :enabled
user = User.new(params[:user])
user.save
end
Cheers
Alok Anand
Rails Detective