How do you log the URL ActiveResource uses?

machineghost picture machineghost · Sep 8, 2010 · Viewed 7.3k times · Source

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})

I would expect that ActiveResource would make a call to:

myIssues.com/issues.xml?page=2

... 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

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 ...

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?

Answer

Jeff Whitmire picture Jeff Whitmire · Nov 11, 2010

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

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.