Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/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 ActiveSupport通知-打印到控制台或日志以进行调试?_Ruby On Rails_Ruby On Rails 3_Activesupport - Fatal编程技术网

Ruby on rails ActiveSupport通知-打印到控制台或日志以进行调试?

Ruby on rails ActiveSupport通知-打印到控制台或日志以进行调试?,ruby-on-rails,ruby-on-rails-3,activesupport,Ruby On Rails,Ruby On Rails 3,Activesupport,我想在更新FbPlace类(mongo文档)的对象时触发新对象的创建。FbPlace仅通过控制台或rake任务中的脚本更新。 是否可以在我的rails s选项卡或我的日志文件中检查我的fb_位置订阅是否正确触发 ActiveSupport::Notifications.subscribe("fb_places_updated.graph_engine") do |*args| puts "WORKS" Rails.logger.debug("+++ WORKS") #Other ir

我想在更新FbPlace类(mongo文档)的对象时触发新对象的创建。FbPlace仅通过控制台或rake任务中的脚本更新。 是否可以在我的
rails s
选项卡或我的日志文件中检查我的fb_位置订阅是否正确触发

ActiveSupport::Notifications.subscribe("fb_places_updated.graph_engine") do |*args|
  puts "WORKS"
  Rails.logger.debug("+++ WORKS")
  #Other irrelevant logic 
end
我添加了
put
Rails.logger.debug
,以查看在执行类似
FbPlace.update\u属性(name:“test\u name”)
的操作时是否触发了通知,但我还没有看到任何打印到控制台或日志文件的内容


有什么建议吗?

您没有指定您实际订阅活动的位置。我会想象你在一个初始化器中完成它,rake任务会加载环境,这样就可以了

要查看在事件发生时对块进行求值,可以使用,这样您只需键入
args
并查看其中的内容。将其放入您的文件中,然后:

ActiveSupport::Notifications.subscribe("fb_places_updated.graph_engine") do |*args|
  binding.pry
end
运行rake任务。如果您没有进入Pry会话,则不会触发该事件。我不确定什么应该触发
fb\u places\u updated.graph\u engine
事件。我认为您使用的是
mongoid
,据我所知,它不会触发任何指令-需要另一面:

ActiveSupport::Notifications.instrument("fb_places_updated.graph_engine", some_data: 42)
如果是这样的话,我就不用担心通知了,只需在模型中使用或