I have been using ActiveResource in my Ruby on Rails applications for some time, and I am starting to really feel that it needs a final polish to make it go from "pretty nice" to "beautiful".
I would like to be able to use an ActiveResource as if it were an ActiveRecord. If I could use has\_many
, belongs\_to
and other niceties with ActiveResources, it would make my life easier.
So I looked around for a plugin to do just that, but haven't had any luck finding one. Has anyone written one? Does anyone know of an ongoing project?
Let's say I have an application which manages Users
, and another application which manages UserRequests
. I would like to avoid any circular dependency between my applications, therefore I have decided that the Users
application will be completely unaware of the notion of UserRequests
. But of course, a UserRequest
should belong to a User
, and a User
should have many UserRequests
.
So, in the Users
application, all I have is a User
ActiveRecord, with all the necessary controller stuff to make it usable through ActiveResource.
The complicated stuff is in the UserRequests
application. I have a UserRequest
ActiveRecord, and a User
ActiveResource. I would love to code the fact that a UserRequest
belongs_to
a User ActiveResource, and a User
ActiveResource has_many
UserRequests
.
In another scenario where it could be the other way around (the ActiveRecord has_many
ActiveResources, and the ActiveResource belongs_to
the ActiveRecord).
I just ran across the Hyperactive Resource plugin. I am looking at it right now... looks good.
The funny thing is that I had decided to write my own plugin, and I was looking for a good name for it. I wanted to find a name which would give the feeling that it was "ActiveResource++", an enhanced version of ActiveResource. I hesitated between "SexyResource" and "HyperactiveResource", and I decided that the former was not politically correct enough. So I started to write my HyperactiveResource plugin... until I wondered if someone else had already thought of that name. And it turns out someone did. And the plugin was there. Cool! But it's kind of scary how we developers think alike, isn't it? ;-)