From 197afc5f5b19f44e6a4ccbdeec6488680311c4ef Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Sat, 19 Feb 2011 04:37:07 +0800 Subject: [PATCH] fixing issue with changing states before an instance is saved --- .../acts_as_state_machine/lib/acts_as_state_machine.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vendor/plugins/acts_as_state_machine/lib/acts_as_state_machine.rb b/vendor/plugins/acts_as_state_machine/lib/acts_as_state_machine.rb index 793ac417..cbbf5f1f 100644 --- a/vendor/plugins/acts_as_state_machine/lib/acts_as_state_machine.rb +++ b/vendor/plugins/acts_as_state_machine/lib/acts_as_state_machine.rb @@ -57,8 +57,11 @@ module ScottBarron #:nodoc: old_state = states[record.current_state] next_state.entering(record) unless loopback - - record.update_attribute(record.class.state_column, to.to_s) + if record.new_record? + record.send(record.class.state_column.to_s + '=', to.to_s) + else + record.update_attribute(record.class.state_column, to.to_s) + end next_state.entered(record) unless loopback old_state.exited(record) unless loopback