ActiveResource in a flurry
Posted by Eric Mill
Apr 26
A look at the Rails Trac’s timeline shows that ActiveResource is undergoing a lot of activity right now, including attention by DHH. Here’s the interesting things I’ve noticed so far:
- Changeset #6539 – If you save an object, and get an XML body response from the controller, reload the object with the data from that response. So, if the controller performs any machinations on an object while saving it, the client can be informed of the object’s new state.
- Changeset #6550 – Replace Action Web Service with ActiveResource.
- Changeset #6584 – Custom method names for resources. This is a big one. I’m inferring what it does by the CHANGELOG comment:
* Added support for calling custom methods #6979 [rwdaigle]
Person.find(:managers) # => GET /people/managers.xml
Kase.find(1).post(:close) # => POST /kases/1/close.xml
- Changeset #6579 – This expands the default scaffold_resource controller to respond to new.xml. It will return a new object, in XML form. This can be used by a client to automatically figure out the attributes a model supports. There’s really no code change here to Rails itself, new.xml is given for free if you want it. The significance is that it expands Rails’ proposed standard for REST.
So altogether, ActiveResource is getting a lot more fleshed out. I can’t help but expect we’re going to see its public release soon, and this is awesome.
Another note: I’ll be supporting that last one, about new.xml, in Jester in the next release, because I submitted the patch for it myself. It’ll significantly benefit Jester, and I suspect any other non-Ruby ActiveResource client out there. I’ll try to keep Jester up to date with ActiveResource, but that’s looking like a tall order.
Comments on this post
Apr 29
Alex MacCaw said,
Could you also support the REST spec in the new version, like expecting 204 responses from DELETE requests. Also, you’ve got an extra comma at the end of a hash (can’t remember what line), so it only works in firefox…. Thanks
Apr 29
Eric Mill said,
Alex – I assume you’re talking about the ActiveResource standards listed in its README, here: README. Or do you mean a more general REST standard?
Two things, though:
Right now, the target audience for Jester is those using Rails-style RESTful controllers. There’s not a lot of common knowledge about these response codes—and the Rails scaffold_resource controller doesn’t use them all. So I’m not going to introduce anything to Jester yet that produces unexpected behavior to people not using these codes. For example, only looking for validation errors if the response code is 422, or assuming an update failed if a 204 wasn’t returned.
The second thing is, that being said, it’d be better if people were following these standards. I’ll submit a patch to Rails to have their scaffold_resource controllers use the codes that their own ARes README says they should be, and I’ll consider enforcing status code responses down the line.
Apr 30
Eric Mill said,
Oh, and thank you for the comma catch—I check IE compatibility “whenever I remember to”, which is obviously not enough, so I’d missed it. I fixed it just before releasing 1.2 this morning.
Sorry, comments are closed for this article.
© 2000 - 2009 by thoughtbot, inc.
written by a bushel of tiny robots
Come “ride the toad” on Hoptoad, the app error app.
Thunder Thimble: Brand monitoring for social media.
Widgetfinger: Simple content management for simple websites.
Tee-Bot, funny shirts your friends won't understand!
Umbrella Today: “It’s like totally the simplest weather report ever, Julie.”
Thoughtbot
thoughtbot is a technology consulting firm that provides web application development and design services. We focus on building modern systems, embracing good ideas and delivering elegant solutions.
Interested in learning Rails?
Sign up for our beginning or advanced training.
Archives