您如何记录ActiveResource使用的URL? [英] How do you log the URL ActiveResource uses?

查看:77
本文介绍了您如何记录ActiveResource使用的URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails ActiveResource非常棒……除了一件事:据我所知,没有办法查看其幕后使用的URL.例如,假设我有一个名为Issue的ActiveResource,用于myIssues.com/issues.xml中的Web服务.如果我这样做:

Rails ActiveResource is awesome ... except for one thing: as far as I can tell, there is no way to see what URL it is using behind the scenes. For instance, let's say I have an ActiveResource called Issue, for a webservice at myIssues.com/issues.xml. If I do:

Issue.find(:all, :params => {:page => 2})

我希望ActiveResource能够致电:

I would expect that ActiveResource would make a call to:

myIssues.com/issues.xml?page=2

...但是我实际上并不知道.就我所知,ActiveResource可能已经决定不喜欢页面"一词,因此它实际上是在使用:

... but I don't actually know that. For all I know, ActiveResource could have decided it doesn't like the word "page", so it's actually using:

myIssues.com/issues.xml?mod_page=2

这使调试困难.现在,我遇到了一种情况,如果转到我认为 ActiveResource使用的URL,它就可以正常工作.但是,当我实际使用ActiveResource时,它不起作用.看到它正在获取的URL将对此有极大的帮助,所以...

This makes debugging difficult. Right now I've got a situation where, if I go to the URL I think ActiveResource is using, it works just fine. However, when I actually use ActiveResource, it doesn't work. Seeing the URL it's GETing would be immensely helpful in this, so ...

有没有人知道一种记录(或以其他方式输出;如果还有一些resource.url方法也能很好地工作)ActiveResource用于执行其操作的URL的方法?

Does anyone know a way to log (or otherwise output; if there's some resource.url method that would work great too) the URL(s) that ActiveResource uses to do its thing?

推荐答案

如果将以下行添加到environment.rb文件中,它将至少记录请求,以便您知道URL ActiveResource正在命中:

If you add the following line to your environment.rb file, it will at least log the requests so you know that URLs ActiveResource is hitting:

ActiveResource::Base.logger = ActiveRecord::Base.logger

我仍在寻找更好的解决方案,以向我显示响应和发布以更新呼叫的数据,但这至少是朝着正确方向迈出的一步.我真的不确定ActiveResource为什么要使用单独的记录器,但这是另一回事.

I'm still searching for a better solution that shows me the response and the data posted to update calls, but at least this is a step in the right direction. I'm really not sure why ActiveResource has a separate logger to start with, but that's another matter.

这篇关于您如何记录ActiveResource使用的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆