Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails ActiveRecord对象在EventMachine回调中不工作_Ruby On Rails_Ruby_Activerecord_Eventmachine_Thin - Fatal编程技术网

Ruby on rails ActiveRecord对象在EventMachine回调中不工作

Ruby on rails ActiveRecord对象在EventMachine回调中不工作,ruby-on-rails,ruby,activerecord,eventmachine,thin,Ruby On Rails,Ruby,Activerecord,Eventmachine,Thin,在测试Rails应用程序时,我遇到了以下问题 使用EventMachine发出异步HTTP请求时,由于某些原因,我无法在回调中使用ActiveRecord对象。 每当我尝试访问该对象时,都会出现以下异常: /home/user/.rvm/gems/ruby-1.8.7-p371/gems/activerecord-2.3.18/lib/active_record/attribute_methods.rb:144:in `create_time_zone_conversion_attribute?

在测试Rails应用程序时,我遇到了以下问题

使用EventMachine发出异步HTTP请求时,由于某些原因,我无法在回调中使用ActiveRecord对象。 每当我尝试访问该对象时,都会出现以下异常:

/home/user/.rvm/gems/ruby-1.8.7-p371/gems/activerecord-2.3.18/lib/active_record/attribute_methods.rb:144:in `create_time_zone_conversion_attribute?': You have a nil object when you didn't expect it! (NoMethodError)
You might have expected an instance of Array.
The error occurred while evaluating nil.include?
from /home/user/.rvm/gems/ruby-1.8.7-p371/gems/activerecord-2.3.18/lib/active_record/attribute_methods.rb:75:in `define_attribute_methods'
from /home/user/.rvm/gems/ruby-1.8.7-p371/gems/activerecord-2.3.18/lib/active_record/attribute_methods.rb:71:in `each'
from /home/user/.rvm/gems/ruby-1.8.7-p371/gems/activerecord-2.3.18/lib/active_record/attribute_methods.rb:71:in `define_attribute_methods'
from /home/user/.rvm/gems/ruby-1.8.7-p371/gems/activerecord-2.3.18/lib/active_record/attribute_methods.rb:257:in `method_missing'
如果我从回调中删除ActiveRecord对象,它可以正常工作。不幸的是,我真的需要他们是可访问的,所以删除不是一个选项

我是否访问对象进行阅读或写作并不重要

我编写的代码如下所示:

http = EM::HttpRequest.new(url).get(:query => query)

http.callback do
  ....
  object.status = 'delivered'
  object.save!
  ....
end
至于环境,我有以下设置:

  • Ubuntu 12.04 LTS
  • Ruby 1.8.7-p371
  • 轨道2.3.18
  • 精简服务器1.5.0
  • ActiveRecord 2.3.18
  • EventMachine 1.0.0
有人知道是什么导致了这个错误吗?如何解决这个问题


提前谢谢

看来我所要做的就是修改我的开发配置文件。
设置config.cache\u classes=true修复了这个问题。

你能展示一下如何获得“object”吗?这太疯狂了,我不得不维护一些旧的Rails 2.3项目。你知道为什么我们会有这个bug吗?不幸的是没有。由于这个修复程序运行得很好,我没有必要再深入研究了。是的,但在开发过程中,每次进行更改时,我们都需要重新启动服务器。或者你知道更好的方法吗?是的,你必须在更改后将cache_类设置为true后重新启动它。但这对我来说从来都不是问题,因为重启只需要几秒钟,而且不经常需要。