我正在開發RoR應用程序。更新到Ruby 2.x和Rails 4.x後,我得到一個CookieOverflowError。爲了解決這個問題,我嘗試使用Active Record Session來存儲會話。我把它用下面的命令:Ruby on Rails活動記錄會話
rails generate active_record:session_migration production
RAILS_ENV=production rake db:migrate
而且改變了我的配置配置/初始化/ session_store.rb AppName的:: Application.config.session_store:active_record_store
這在日誌/生產會.log file:
ArgumentError (wrong number of arguments (1 for 2)):
vendor/bundle/ruby/2.1.0/gems/arel-5.0.0/lib/arel/crud.rb:5:in `compile_update'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/persistence.rb:500:in `update_record'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/locking/optimistic.rb:70:in `update_record'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/attribute_methods/dirty.rb:74:in `update_record'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/callbacks.rb:310:in `block in update_record'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/callbacks.rb:373:in `_run__4115952957871857265__update__callbacks'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/callbacks.rb:80:in `run_callbacks'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/callbacks.rb:310:in `update_record'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/timestamp.rb:70:in `update_record'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/persistence.rb:478:in `create_or_update'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/callbacks.rb:302:in `block in create_or_update'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/callbacks.rb:393:in `_run__4115952957871857265__save__callbacks'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/callbacks.rb:80:in `run_callbacks'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/callbacks.rb:302:in `create_or_update'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/persistence.rb:103:in `save'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/validations.rb:51:in `save'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/attribute_methods/dirty.rb:32:in `save'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/transactions.rb:270:in `block (2 levels) in save'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/transactions.rb:330:in `block in with_transaction_returning_status'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/database_statements.rb:221:in `within_new_transaction'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/transactions.rb:209:in `transaction'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/transactions.rb:327:in `with_transaction_returning_status'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/transactions.rb:270:in `block in save'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/transactions.rb:285:in `rollback_active_record_state!'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/transactions.rb:269:in `save'
vendor/bundle/ruby/2.1.0/bundler/gems/activerecord-session_store-55dc59aff9a1/lib/action_dispatch/session/active_record_store.rb:80:in `block in set_session'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/reporting.rb:110:in `block (2 levels) in quietly'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/reporting.rb:50:in `silence_stream'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/reporting.rb:109:in `block in quietly'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/reporting.rb:50:in `silence_stream'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/core_ext/kernel/reporting.rb:108:in `quietly'
vendor/bundle/ruby/2.1.0/bundler/gems/activerecord-session_store-55dc59aff9a1/lib/action_dispatch/session/active_record_store.rb:77:in `set_session'
vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:342:in `commit_session'
vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:226:in `context'
vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/cookies.rb:486:in `call'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/query_cache.rb:36:in `call'
vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/callbacks.rb:373:in `_run__2968889427859779895__call__callbacks'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/callbacks.rb:80:in `run_callbacks'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
vendor/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/rack/logger.rb:38:in `call_app'
vendor/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/rack/logger.rb:20:in `block in call'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/tagged_logging.rb:68:in `block in tagged'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/tagged_logging.rb:26:in `tagged'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/tagged_logging.rb:68:in `tagged'
vendor/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/rack/logger.rb:20:in `call'
vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/request_id.rb:21:in `call'
vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.4/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
vendor/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/engine.rb:511:in `call'
vendor/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/application.rb:97:in `call'
vendor/bundle/ruby/2.1.0/gems/railties-4.0.4/lib/rails/railtie/configurable.rb:30:in `method_missing'
/usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.40/lib/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
/usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.40/lib/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
/usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.40/lib/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
/usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.40/lib/phusion_passenger/request_handler.rb:448:in `block (3 levels) in start_threads'
我創建了一個單獨的日誌文件,它打印記錄的內容,在該文件上調用方法保存。這是保存失敗的方法(active_record_store.rb)。
D, [2014-04-04T11:18:09.058984 #31574] DEBUG -- : #<ActiveRecord::SessionStore::Session id: 1, session_id: "11f19fdf6d404a4667f11458bedf157f", data: "BAh7BkkiEGluaXRpYWxfdXJpBjoGRVRJIi1odHRwczovL2ljb3N...", created_at: "2014-04-04 08:47:18", updated_at: "2014-04-04 08:47:18">
從鐵軌控制檯:
2.1.1 :001 > ActiveRecord::Base.connection.tables
=> ["schema_migrations", "items", "roles", "rights", "roles_users", "rights_roles", "users", "queue_messages", "mammie_tokens", "sessions"]
2.1.1 :002 > ActiveRecord::Base.connection.columns('sessions')
=> [#<ActiveRecord::ConnectionAdapters::SQLite3Column:0x00000002a80078 @name="id", @sql_type="INTEGER", @null=false, @limit=nil, @precision=nil, @scale=nil, @type=:integer, @default=nil, @default_function=nil, @primary=nil, @coder=nil>, #<ActiveRecord::ConnectionAdapters::SQLite3Column:0x00000002a62a00 @name="session_id", @sql_type="varchar(255)", @null=false, @limit=255, @precision=nil, @scale=nil, @type=:string, @default=nil, @default_function=nil, @primary=nil, @coder=nil>, #<ActiveRecord::ConnectionAdapters::SQLite3Column:0x00000002a60c00 @name="data", @sql_type="text", @null=true, @limit=nil, @precision=nil, @scale=nil, @type=:text, @default=nil, @default_function=nil, @primary=nil, @coder=nil>, #<ActiveRecord::ConnectionAdapters::SQLite3Column:0x00000002a60840 @name="created_at", @sql_type="datetime", @null=true, @limit=nil, @precision=nil, @scale=nil, @type=:datetime, @default=nil, @default_function=nil, @primary=nil, @coder=nil>, #<ActiveRecord::ConnectionAdapters::SQLite3Column:0x00000002a602c8 @name="updated_at", @sql_type="datetime", @null=true, @limit=nil, @precision=nil, @scale=nil, @type=:datetime, @default=nil, @default_function=nil, @primary=nil, @coder=nil>]
活動記錄自己的日誌文件:
# Logfile created on 2014-04-04 13:13:35 +0200 by logger.rb/44203
D, [2014-04-04T13:13:37.163858 #11512] DEBUG -- : ActiveRecord::SessionStore::Session Load (0.3ms) SELECT "sessions".* FROM "sessions" WHERE "sessions"."session_id" = '871b57e38039360f4aeaa61857e90605' ORDER BY "sessions"."id" ASC LIMIT 1
D, [2014-04-04T13:13:37.176779 #11512] DEBUG -- : User Load (0.3ms) SELECT "users".* FROM "users" WHERE (UPPER(username) = 'ADMINISTRATOR' and hashed_pasword = 'HASH') ORDER BY "users"."id" ASC LIMIT 1
D, [2014-04-04T13:13:37.216335 #11512] DEBUG -- : (0.1ms) begin transaction
D, [2014-04-04T13:13:37.241415 #11512] DEBUG -- : SQL (20.6ms) INSERT INTO "mammie_tokens" ("created_at", "token", "updated_at") VALUES (?, ?, ?) [["created_at", Fri, 04 Apr 2014 11:13:37 UTC +00:00], ["token", "token_17a75000-9518-0131-0160-2565bbb3839e"], ["updated_at", Fri, 04 Apr 2014 11:13:37 UTC +00:00]]
D, [2014-04-04T13:13:37.252799 #11512] DEBUG -- : (10.8ms) commit transaction
D, [2014-04-04T13:13:37.264598 #11512] DEBUG -- : (0.2ms) begin transaction
D, [2014-04-04T13:13:37.272679 #11512] DEBUG -- : (0.2ms) rollback transaction
不過,我一直一遍遍得到同樣的錯誤,如不順心的事時, (我猜)有些東西正在被保存。
有什麼建議嗎?
我應該在我的帖子中包含哪些內容?我的猜測是ActiveRecord本身無法正常工作,有沒有什麼方法可以測試它? –
ActiveRecord已經過測試並且測試良好。您可以運行測試來檢查它。您可以運行測試用例請注意您使用它的方式有些問題。大多數我們遇到的錯誤可能是對寶石的誤解。如果遇到限制,也可以開源,您可以隨時更改以適應自己的需求。 –
我創建了一個單獨的日誌文件,它打印記錄的內容,在該記錄上調用方法保存。這是保存失敗的方法(active_record_store.rb)。 # 在我看來,這個記錄無論在任何方面都沒有錯,或者我在這裏錯過了什麼? –