我收到ActiveRecord :: ReadOnlyRecord错误但无法理解在哪个查询中。
那么请帮助找出具有ReadOnly Access的查询。
当我创建新记录然后无法获得错误时,我只有在更新记录时才会出错。
以下是我的日志。
控制器 - 提供商
def update
if @provider.update_attributes(params[:provider])
flash[:notice] = "Saved changes to <strong>#{@provider.name}</strong>".html_safe
redirect_to edit_clinic_provider_url(@provider.clinic, @provider) << "##{params[:anchor]}"
else
render :action => 'edit', :anchor => params[:anchor]
end
end
后端日志
Processing by ProvidersController#update as HTML
Parameters: {"anchor"=>"contact", "utf8"=>"✓", "authenticity_token"=>"lWW6ifXtHDYPbFclDpS1QJ7cm+tMJn2zTa7J7cUNUDg=", "provider"=>{"clinic_id"=>"2", "signature_name"=>"Dimple Clinic", "provider_type_code"=>"Medical Doctor", "tax_uid"=>"111-11-1111", "upin_uid"=>"1111111111", "npi_uid"=>"1111111111", "contact_attributes"=>{"first_name"=>"DImple", "last_name"=>"Panchal", "phone1"=>"1111111111", "phone1_ext"=>"1", "fax1"=>"", "email1"=>"", "id"=>"10"}, "notes"=>"Test"}, "clinic_id"=>"2", "id"=>"2"}
Account Load (0.3ms) SELECT "accounts".* FROM "accounts" WHERE "accounts"."deleted_at" IS NULL AND "accounts"."full_domain" = 'localhost' LIMIT 1
User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 AND ("users".account_id = 2) LIMIT 1
Clinic Load (0.3ms) SELECT "clinics".* FROM "clinics" WHERE "clinics"."deleted_at" IS NULL AND "clinics"."id" = 2 AND ("clinics".account_id = 2) LIMIT 1
CACHE (0.0ms) SELECT "clinics".* FROM "clinics" WHERE "clinics"."deleted_at" IS NULL AND "clinics"."id" = 2 AND ("clinics".account_id = 2) LIMIT 1
DEPRECATION WARNING: Base.named_scope has been deprecated, please use Base.scope instead. (called from included at (eval):1)
Provider Load (2.2ms) SELECT "providers"."id" AS t0_r0, "providers"."signature_name" AS t0_r1, "providers"."provider_type_code" AS t0_r2, "providers"."tax_uid" AS t0_r3, "providers"."upin_uid" AS t0_r4, "providers"."license" AS t0_r5, "providers"."notes" AS t0_r6, "providers"."nycomp_testify" AS t0_r7, "providers"."npi_uid" AS t0_r8, "providers"."contact_id" AS t0_r9, "providers"."address_id" AS t0_r10, "providers"."deleted_at" AS t0_r11, "providers"."created_at" AS t0_r12, "providers"."updated_at" AS t0_r13, "providers"."clinic_id" AS t0_r14, "contacts"."id" AS t1_r0, "contacts"."first_name" AS t1_r1, "contacts"."last_name" AS t1_r2, "contacts"."company_name" AS t1_r3, "contacts"."phone1" AS t1_r4, "contacts"."phone2" AS t1_r5, "contacts"."phone1_ext" AS t1_r6, "contacts"."phone2_ext" AS t1_r7, "contacts"."attention" AS t1_r8, "contacts"."notes" AS t1_r9, "contacts"."deleted_at" AS t1_r10, "contacts"."created_at" AS t1_r11, "contacts"."updated_at" AS t1_r12, "contacts"."title" AS t1_r13, "contacts"."phone3" AS t1_r14, "contacts"."phone3_ext" AS t1_r15, "contacts"."contactable_id" AS t1_r16, "contacts"."contactable_type" AS t1_r17, "contacts"."email1" AS t1_r18, "contacts"."email2" AS t1_r19, "contacts"."fax1" AS t1_r20, "contacts"."sex" AS t1_r21, "contacts"."occupation" AS t1_r22, "contacts"."middle_initial" AS t1_r23 FROM "providers" LEFT OUTER JOIN "contacts" ON "contacts"."id" = "providers"."contact_id" INNER JOIN "clinics" ON "providers".clinic_id = "clinics".id WHERE "providers"."deleted_at" IS NULL AND "providers"."id" = 2 AND (("clinics".account_id = 2)) ORDER BY contacts.last_name ASC, contacts.first_name ASC LIMIT 1
Clinic Load (0.3ms) SELECT "clinics".* FROM "clinics" WHERE "clinics"."deleted_at" IS NULL AND "clinics"."id" = 2 LIMIT 1
Provider Load (0.1ms) SELECT "providers"."id" FROM "providers" WHERE ("providers"."signature_name" = 'Dimple Clinic') AND ("providers".id <> 2) LIMIT 1
Completed in 435ms
ActiveRecord::ReadOnlyRecord (ActiveRecord::ReadOnlyRecord):
activerecord (3.0.5) lib/active_record/persistence.rb:245:in `create_or_update'
activerecord (3.0.5) lib/active_record/callbacks.rb:277:in `block in create_or_update'
activesupport (3.0.5) lib/active_support/callbacks.rb:428:in `_run_save_callbacks'
activerecord (3.0.5) lib/active_record/callbacks.rb:277:in `create_or_update'
activerecord (3.0.5) lib/active_record/persistence.rb:39:in `save'
activerecord (3.0.5) lib/active_record/validations.rb:43:in `save'
activerecord (3.0.5) lib/active_record/attribute_methods/dirty.rb:21:in `save'
activerecord (3.0.5) lib/active_record/transactions.rb:240:in `block (2 levels) in save'
activerecord (3.0.5) lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
activerecord (3.0.5) lib/active_record/transactions.rb:207:in `transaction'
activerecord (3.0.5) lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
activerecord (3.0.5) lib/active_record/transactions.rb:240:in `block in save'
activerecord (3.0.5) lib/active_record/transactions.rb:251:in `rollback_active_record_state!'
activerecord (3.0.5) lib/active_record/transactions.rb:239:in `save'
activerecord (3.0.5) lib/active_record/persistence.rb:128:in `block in update_attributes'
activerecord (3.0.5) lib/active_record/transactions.rb:292:in `block in with_transaction_returning_status'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
activerecord (3.0.5) lib/active_record/transactions.rb:207:in `transaction'
activerecord (3.0.5) lib/active_record/transactions.rb:290:in `with_transaction_returning_status'
activerecord (3.0.5) lib/active_record/persistence.rb:126:in `update_attributes'
app/controllers/providers_controller.rb:59:in `update'
actionpack (3.0.5) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (3.0.5) lib/abstract_controller/base.rb:150:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/rendering.rb:11:in `process_action'
actionpack (3.0.5) lib/abstract_controller/callbacks.rb:18:in `block in process_action'
activesupport (3.0.5) lib/active_support/callbacks.rb:480:in `_run__1006169370__process_action__404846983__callbacks'
activesupport (3.0.5) lib/active_support/callbacks.rb:409:in `_run_process_action_callbacks'
activesupport (3.0.5) lib/active_support/callbacks.rb:93:in `run_callbacks'
actionpack (3.0.5) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `block in instrument'
activesupport (3.0.5) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
activesupport (3.0.5) lib/active_support/notifications.rb:52:in `instrument'
actionpack (3.0.5) lib/action_controller/metal/instrumentation.rb:29:in `process_action'
actionpack (3.0.5) lib/action_controller/metal/rescue.rb:17:in `process_action'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:30:in `block in process_action'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/controller_instrumentation.rb:362:in `perform_action_with_newrelic_trace'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/rails3/action_controller.rb:29:in `process_action'
actionpack (3.0.5) lib/abstract_controller/base.rb:119:in `process'
actionpack (3.0.5) lib/abstract_controller/rendering.rb:41:in `process'
actionpack (3.0.5) lib/action_controller/metal.rb:138:in `dispatch'
actionpack (3.0.5) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.0.5) lib/action_controller/metal.rb:178:in `block in action'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:62:in `call'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:62:in `dispatch'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:27:in `call'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:148:in `block in call'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:93:in `block in recognize'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:117:in `optimized_each'
rack-mount (0.6.14) lib/rack/mount/code_generation.rb:92:in `recognize'
rack-mount (0.6.14) lib/rack/mount/route_set.rb:139:in `call'
actionpack (3.0.5) lib/action_dispatch/routing/route_set.rb:492:in `call'
hoptoad_notifier (2.4.11) lib/hoptoad_notifier/rack.rb:27:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/head.rb:14:in `call'
rack (1.2.8) lib/rack/methodoverride.rb:24:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/flash.rb:182:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/session/abstract_store.rb:149:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/cookies.rb:302:in `call'
activerecord (3.0.5) lib/active_record/query_cache.rb:32:in `block in call'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/query_cache.rb:28:in `cache'
activerecord (3.0.5) lib/active_record/query_cache.rb:12:in `cache'
activerecord (3.0.5) lib/active_record/query_cache.rb:31:in `call'
activerecord (3.0.5) lib/active_record/connection_adapters/abstract/connection_pool.rb:354:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/callbacks.rb:46:in `block in call'
activesupport (3.0.5) lib/active_support/callbacks.rb:415:in `_run_call_callbacks'
actionpack (3.0.5) lib/action_dispatch/middleware/callbacks.rb:44:in `call'
rack (1.2.8) lib/rack/sendfile.rb:106:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.0.5) lib/rails/rack/logger.rb:13:in `call'
rack (1.2.8) lib/rack/runtime.rb:17:in `call'
activesupport (3.0.5) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.2.8) lib/rack/lock.rb:13:in `block in call'
<internal:prelude>:10:in `synchronize'
rack (1.2.8) lib/rack/lock.rb:13:in `call'
newrelic_rpm (3.14.0.305) lib/new_relic/agent/instrumentation/middleware_tracing.rb:78:in `call'
actionpack (3.0.5) lib/action_dispatch/middleware/static.rb:30:in `call'
hoptoad_notifier (2.4.11) lib/hoptoad_notifier/user_informer.rb:12:in `call'
railties (3.0.5) lib/rails/application.rb:168:in `call'
railties (3.0.5) lib/rails/application.rb:77:in `method_missing'
railties (3.0.5) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.2.8) lib/rack/content_length.rb:13:in `call'
rack (1.2.8) lib/rack/handler/webrick.rb:52:in `service'
/home/dipak/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/home/dipak/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/home/dipak/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Rendered /home/dipak/.rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.2ms)
Provider Load (36.7ms) SELECT "providers"."id" AS t0_r0, "providers"."signature_name" AS t0_r1, "providers"."provider_type_code" AS t0_r2, "providers"."tax_uid" AS t0_r3, "providers"."upin_uid" AS t0_r4, "providers"."license" AS t0_r5, "providers"."notes" AS t0_r6, "providers"."nycomp_testify" AS t0_r7, "providers"."npi_uid" AS t0_r8, "providers"."contact_id" AS t0_r9, "providers"."address_id" AS t0_r10, "providers"."deleted_at" AS t0_r11, "providers"."created_at" AS t0_r12, "providers"."updated_at" AS t0_r13, "providers"."clinic_id" AS t0_r14, "contacts"."id" AS t1_r0, "contacts"."first_name" AS t1_r1, "contacts"."last_name" AS t1_r2, "contacts"."company_name" AS t1_r3, "contacts"."phone1" AS t1_r4, "contacts"."phone2" AS t1_r5, "contacts"."phone1_ext" AS t1_r6, "contacts"."phone2_ext" AS t1_r7, "contacts"."attention" AS t1_r8, "contacts"."notes" AS t1_r9, "contacts"."deleted_at" AS t1_r10, "contacts"."created_at" AS t1_r11, "contacts"."updated_at" AS t1_r12, "contacts"."title" AS t1_r13, "contacts"."phone3" AS t1_r14, "contacts"."phone3_ext" AS t1_r15, "contacts"."contactable_id" AS t1_r16, "contacts"."contactable_type" AS t1_r17, "contacts"."email1" AS t1_r18, "contacts"."email2" AS t1_r19, "contacts"."fax1" AS t1_r20, "contacts"."sex" AS t1_r21, "contacts"."occupation" AS t1_r22, "contacts"."middle_initial" AS t1_r23 FROM "providers" LEFT OUTER JOIN "contacts" ON "contacts"."id" = "providers"."contact_id" INNER JOIN "clinics" ON "providers".clinic_id = "clinics".id WHERE "providers"."deleted_at" IS NULL AND (("clinics".account_id = 2)) ORDER BY contacts.last_name ASC, contacts.first_name ASC
Rendered /home/dipak/.rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (47.5ms)
Rendered /home/dipak/.rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.0.5/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (52.2ms)
答案 0 :(得分:2)
使用ActiveRecord连接有时会导致生成的记录为只读。您可以通过将.readonly(false)
链接到AR关系来解决此问题。您尚未显示代码中@provider
的设置方式,但以下是将readonly设置为false的要点:
@provider = Provider.joins(...).where(...).readonly(false).find(params[:id])