#116 ✓resolved
Patrick Anderson

ActiveRecord::ReadOnlyRecord error on login using authenticates_many with Rails 2.3.2

Reported by Patrick Anderson | June 3rd, 2009 @ 06:22 PM

Following the example code from your site, I've set up a User model, a UserSession model, and a UserSessionsController. I have a UserGroup model which I want to use to scope the logins to a particular user group using authenticates_many. Unfortunately, my controller's create method throws a ActiveRecord::ReadOnlyRecord error, which seems to be caused by the magic fields trying to update on my User model. If I ignore the error and manually enter a url which uses the require_user filter, I appear to be logged in. I get the same error if I use a bad password.

The stack trace follows:

/trinity/www/ruby_v2/vendor/rails/activerecord/lib/active_record/base.rb:2867:in `create_or_update_without_callbacks'
/trinity/www/ruby_v2/vendor/rails/activerecord/lib/active_record/callbacks.rb:250:in `create_or_update'
/trinity/www/ruby_v2/vendor/rails/activerecord/lib/active_record/base.rb:2539:in `save_without_validation'
/trinity/www/ruby_v2/vendor/rails/activerecord/lib/active_record/validations.rb:1009:in `save_without_dirty'
/trinity/www/ruby_v2/vendor/rails/activerecord/lib/active_record/dirty.rb:79:in `save_without_transactions'
/trinity/www/ruby_v2/vendor/rails/activerecord/lib/active_record/transactions.rb:229:in `send'
/trinity/www/ruby_v2/vendor/rails/activerecord/lib/active_record/transactions.rb:229:in `with_transaction_returning_status'
/trinity/www/ruby_v2/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
/trinity/www/ruby_v2/vendor/rails/activerecord/lib/active_record/transactions.rb:182:in `transaction'
/trinity/www/ruby_v2/vendor/rails/activerecord/lib/active_record/transactions.rb:228:in `with_transaction_returning_status'
/trinity/www/ruby_v2/vendor/rails/activerecord/lib/active_record/transactions.rb:196:in `save'
/trinity/www/ruby_v2/vendor/rails/activerecord/lib/active_record/transactions.rb:208:in `rollback_active_record_state!'
/trinity/www/ruby_v2/vendor/rails/activerecord/lib/active_record/transactions.rb:196:in `save'
/trinity/www/ruby_v2/vendor/plugins/authlogic/lib/authlogic/acts_as_authentic/session_maintenance.rb:73:in `save_without_session_maintenance'
/trinity/www/ruby_v2/vendor/plugins/authlogic/lib/authlogic/session/callbacks.rb:83:in `save_record'
/trinity/www/ruby_v2/vendor/plugins/authlogic/lib/authlogic/session/priority_record.rb:30:in `save_record'
/trinity/www/ruby_v2/vendor/plugins/authlogic/lib/authlogic/session/validation.rb:66:in `valid?'
/trinity/www/ruby_v2/vendor/plugins/authlogic/lib/authlogic/session/existence.rb:63:in `save'
/trinity/www/ruby_v2/app/controllers/admin/user_sessions_controller.rb:18:in `create'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/base.rb:1322:in `send'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/base.rb:1322:in `perform_action_without_filters'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/filters.rb:617:in `call_filters'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/trinity/www/ruby_v2/vendor/rails/activesupport/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/trinity/www/ruby_v2/vendor/rails/activesupport/lib/active_support/core_ext/benchmark.rb:10:in `realtime'
/trinity/www/ruby_v2/vendor/rails/activesupport/lib/active_support/core_ext/benchmark.rb:17:in `ms'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/rescue.rb:160:in `perform_action_without_flash'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/flash.rb:141:in `perform_action'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/base.rb:523:in `send'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/base.rb:523:in `process_without_filters'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/filters.rb:606:in `process'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/base.rb:391:in `process'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/base.rb:386:in `call'
/trinity/www/ruby_v2/vendor/rails/actionpack/lib/action_controller/routing/route_set.rb:433:in `call'

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson June 24th, 2009 @ 02:00 AM

    • State changed from “new” to “resolved”

    If your record is read only why do you have the fields in the db in the first place? You might try removing them if you don't need them and this error should go away. But I will put a check in for readonly so it will skip this. Thanks!

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Object based authentication solution that handles all of the non sense for you. It's as easy as ActiveRecord is with a database.

People watching this ticket

Pages