Saturday, May 10, 2008

Actionwebservice and rails 2.0

Recently the management of a project of i was working on decided that we should upgrade our application to Rails 2.0. I instantly started to salivate, my mind listing all the fine new features I could finally make use of ( the application had been frozen to 1.2.3 ). So I sallied forth and jumped head first into making the upgrade.

For the most part the upgrade was easy, a handful of deprecated method calls had to be re-factored. No big deal.. The hard part of this upgrade is: The application communicates with mobile devices through XMLRPC. So, we need to maintain actionwebservice.. Sure I’d love to re-factor the whole application to REST but rewriting the Windows Mobile application in the client devices is not an option.

Before i lose you I’ll stop telling the story and jump into the how-to:

First. If you haven’t read the ‘Freezing and Autoloading Gems’ aritcle click ‘back’ and do that first as these steps build on that practice.

Don’t.. that is DO NOT try to unpack a version of actionwebservice gem into your vendor/gems directory I tried several different versions and none of them worked.. complaints about missing methods and such..

Do however checkout actionwebservice from it’s svn trunk

cd vendor/gems/
svn co actionwebservice

once actionwebservice is installed add to your environment or an initializer.

require 'actionwebservice'

At first glance you might think you’re done. but i seems to have to add one more tweak to get things working for me. I needed to add my web service API definition to my load path. so i went back to environment.rb and added the following.

config.load_paths += %W( #{RAILS_ROOT}/app/apis )

Finally, to ensure that your tests will run (you are testing your api, right?) open your test_helper.rb or your spec_helper.rb and add the following line

require 'action_web_service/test_invoke'

And that allows your legacy web service API to ride modern rails..