ErwinM/acts_as_tenant — pull request #2 by nickveys (2012-01-28 02:16:04+00:00)
Title: Rails 3.2 write_attribute fix

Updating to Rails 3.2 causes failure when injecting the tenant association on new objects. The attribute isn't there yet, and fails. The only attributes that are available at the time are the database columns themselves, so instead of using object.account, I used object.account_id and all is well.

Possibly related: https://github.com/rails/rails/issues/4583

Guessing it's this commit: https://github.com/rails/rails/commit/50d395f96ea05da1e02459688e94bff5872c307b

Full stack trace of the failure:
```
/Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/attribute_methods/write.rb:34:in `write_attribute': can't write unknown attribute `account' (ActiveModel::MissingAttributeError)
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/attribute_methods/dirty.rb:67:in `write_attribute'
from /Volumes/Aramis/acts_as_tenant.git/lib/acts_as_tenant/model_extensions.rb:62:in `block in acts_as_tenant'
from /Volumes/Aramis/acts_as_tenant.git/lib/acts_as_tenant/model_extensions.rb:43:in `block in acts_as_tenant'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:407:in `_run__2098072948231748962__validation__677429581214301363__callbacks'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:405:in `__run_callback'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:385:in `_run_validation_callbacks'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activesupport-3.2.1/lib/active_support/callbacks.rb:81:in `run_callbacks'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activemodel-3.2.1/lib/active_model/validations/callbacks.rb:53:in `run_validations!'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activemodel-3.2.1/lib/active_model/validations.rb:179:in `valid?'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/validations.rb:69:in `valid?'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/validations.rb:77:in `perform_validations'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/validations.rb:50:in `save'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/attribute_methods/dirty.rb:22:in `save'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/transactions.rb:241:in `block (2 levels) in save'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/transactions.rb:295:in `block in with_transaction_returning_status'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/connection_adapters/abstract/database_statements.rb:190:in `transaction'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/transactions.rb:208:in `transaction'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/transactions.rb:293:in `with_transaction_returning_status'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/transactions.rb:241:in `block in save'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/transactions.rb:252:in `rollback_active_record_state!'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/transactions.rb:240:in `save'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/activerecord-3.2.1/lib/active_record/persistence.rb:45:in `create'
from /Volumes/Aramis/acts_as_tenant.git/spec/model_extensions_spec.rb:221:in `block (2 levels) in '
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:201:in `module_eval'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:201:in `subclass'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:187:in `describe'
from /Volumes/Aramis/acts_as_tenant.git/spec/model_extensions_spec.rb:218:in `block in '
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:201:in `module_eval'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:201:in `subclass'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/example_group.rb:187:in `describe'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/dsl.rb:18:in `describe'
from /Volumes/Aramis/acts_as_tenant.git/spec/model_extensions_spec.rb:78:in `'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `block in load_spec_files'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `map'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/configuration.rb:698:in `load_spec_files'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/command_line.rb:22:in `run'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:80:in `run_in_process'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:69:in `run'
from /Users/nick/.rvm/gems/ruby-1.9.2-p290@rails31/gems/rspec-core-2.8.0/lib/rspec/core/runner.rb:10:in `block in autorun'
```