diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 7363a125..3831e82d 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,5 +1,7 @@ == master +* Fix mass-assignment sanitization breaking in ActiveRecord 3.0.0 beta5+ [Akira Matsuda] + == 0.9.3 / 2010-06-26 * Allow access to human state / event names in transitions and for the current state diff --git a/lib/state_machine/integrations/active_record.rb b/lib/state_machine/integrations/active_record.rb index af771cdf..c163a758 100644 --- a/lib/state_machine/integrations/active_record.rb +++ b/lib/state_machine/integrations/active_record.rb @@ -415,12 +415,16 @@ def attributes=(new_attributes, *args) if new_record? && !@initialized_state_machines @initialized_state_machines = true - if new_attributes + ignore = if new_attributes attributes = new_attributes.dup attributes.stringify_keys! - ignore = remove_attributes_protected_from_mass_assignment(attributes).keys + if ::ActiveRecord::VERSION::MAJOR >= 3 + sanitize_for_mass_assignment(attributes).keys + else + remove_attributes_protected_from_mass_assignment(attributes).keys + end else - ignore = [] + [] end initialize_state_machines(:dynamic => false, :ignore => ignore)