升级Rails应用程序到Ruby 1.9.2 - 类DateTime需要有方法`_load'

时间:2012-02-22 01:46:16

标签: ruby ruby-on-rails-3 activesupport

自从我将我的应用程序升级到ruby 1.9.2后,我收到以下错误:

我正在运行ruby -v ruby 1.9.2p290(2011-07-09修订版32553)[x86_64-darwin11.2.0]

TypeError (class DateTime needs to have method `_load'):
  activesupport (3.2.1) lib/active_support/message_verifier.rb:45:in `load'
  activesupport (3.2.1) lib/active_support/message_verifier.rb:45:in `verify'
  actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:288:in `[]'
  actionpack (3.2.1) lib/action_dispatch/middleware/session/cookie_store.rb:53:in `block in unpacked_cookie_data'
  actionpack (3.2.1) lib/action_dispatch/middleware/session/abstract_store.rb:55:in `stale_session_check!'
  actionpack (3.2.1) lib/action_dispatch/middleware/session/cookie_store.rb:51:in `unpacked_cookie_data'
  rack (1.4.1) lib/rack/session/cookie.rb:98:in `extract_session_id'
  actionpack (3.2.1) lib/action_dispatch/middleware/session/abstract_store.rb:51:in `block in extract_session_id'
  actionpack (3.2.1) lib/action_dispatch/middleware/session/abstract_store.rb:55:in `stale_session_check!'
  actionpack (3.2.1) lib/action_dispatch/middleware/session/abstract_store.rb:51:in `extract_session_id'
  rack (1.4.1) lib/rack/session/abstract/id.rb:43:in `load_session_id!'
  rack (1.4.1) lib/rack/session/abstract/id.rb:32:in `[]'
  rack (1.4.1) lib/rack/session/abstract/id.rb:262:in `current_session_id'
  rack (1.4.1) lib/rack/session/abstract/id.rb:268:in `session_exists?'
  rack (1.4.1) lib/rack/session/abstract/id.rb:107:in `exists?'
  rack (1.4.1) lib/rack/session/abstract/id.rb:122:in `load_for_read!'
  rack (1.4.1) lib/rack/session/abstract/id.rb:64:in `has_key?'
  actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:258:in `ensure in call'
  actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:259:in `call'
  rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
  rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:338:in `call'
  activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call'
  activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
  activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__3195440498508246587__call__1658952344890015472__callbacks'
  activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
  activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
  activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call'
  railties (3.2.1) lib/rails/engine.rb:479:in `call'
  railties (3.2.1) lib/rails/application.rb:220:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /Users/guillaumenm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
  /Users/guillaumenm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
  /Users/guillaumenm/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'

我创建了一个新的rails应用程序,没有问题启动它。我之前没有任何问题。

这是我的宝石文件。任何帮助都会非常受欢迎。

由于

source :gemcutter

gem 'oauth2'
gem 'faraday'
gem "koala", "~> 1.2.0beta"
gem 'json'
gem "rails", "3.2.1"
gem "sqlite3-ruby", :require => "sqlite3" 
gem 'songkickr'
gem 'httparty'
gem "squeel" , "~> 0.9.5" 
group :development do
  gem 'dalli'  #To use memcached
  gem 'newrelic_rpm'
  gem 'rails-web-console', :require => 'console'
  gem 'heroku'
end

gem 'event-calendar', :require => 'event_calendar'
gem 'delayed_job', '2.1.4'
gem 'icalendar'
gem 'acts_as_tree'
gem 'active_scaffold'
gem 'prototype-rails' 
gem 'prototype_legacy_helper', '0.0.0'  , :git => 'git://github.com/rails/prototype_legacy_helper.git'
gem "state_machine"

只是将我的应用降级到之前的工作轨道3.1.2,没有更多的成功。与ruby 1.9.2升级有关。

3 个答案:

答案 0 :(得分:0)

在stackoverflow上找到答案:

Local server error after upgrading ruby from 1.8.7 to 1.9.2 (with Rails 3.1.1)

清除您的Cookie:您的应用程序正在将Cookie中的会话(这是一个已编组的ruby对象)存储起来。如果我没记错的话,他的编组格式在1.8和1.9之间变化,所以你的应用程序无法再加载旧会话

我的应用程序不是生产应用程序,或者我可能有很多用户遇到这些错误......

答案 1 :(得分:0)

在更新生产应用程序时,我能够通过清除所有会话来解决此问题:

DELETE FROM sessions;

(使用SQL从数据库 - 所以用户不必清除他们的cookie)

答案 2 :(得分:0)

最近发生了类似的事情。经过一些调试(甚至调试ruby代码来确认),我的结论是plist4r gem正在修改String类,使其成为user-serializable()。更新后,当我们删除plist4r的依赖项时,String实例被还原为system-deserializable。但序列化的流仍然需要String实例是用户可反序列化的,因此错误。

对我来说就是plist4r和String类https://github.com/dreamcat4/plist4r/blob/master/lib/plist4r/backend/ruby_cocoa.rb

的情况

可能还有其他一些案例。

我们的解决方案是使所有会话(数据/ cookie)无效,从而无需对这些流进行反序列化。