What's New in Edge Rails: No REST for the weary

Posted by Nathaniel Bibler August 20, 2009 @ 03:01 PM

This week's post will be rather short and sweet. The notable commits of the week seemed to revolve mainly around refactoring and even slightly altering the way some of the bits work. Lets get into it:

I'm Partially impressed

Yehuda Katz was able to simplify some of the partial rendering logic this week, although in doing so seems to very slightly alter the call methodology. So now, when calling the local object from within a partial, you will have the choice of using either the partial name (i.e. "_post.html.erb" would be "post") as the reference for the local object, or you may make it unique by passing in the :as option (i.e. render :partial => "post", :as => "poster_boy" would be "poster_boy"). You no longer have the option of using both interchangeably from within your partial. Also, the :object option for render :partial has been removed, in favor of the methods previously mentioned.

We won't Accept it

The way in which Rails handles incoming Accept headers has been updated. This was primarily due to the fact that web browsers do not always seem to know what they want ... let alone are able to consistently articulate it. So, Accept headers are now only used for XHR requests or single item headers - meaning they're not requesting everything. If that fails, we fall back to using the params[:format].

It's also worth noting that requests to an action in which you've only declared an XML template will no longer be automatically rendered for an HTML request (browser request). This had previously worked, not necessarily by design, but because most browsers send a catch-all Accept header ("*/*"). So, if you want to serve XML directly to a browser, be sure to provide the :xml format or explicitly specify the XML template (render "template.xml").

I'll tell you where you can go...

Josh Peek finally removed the deprecated "best fit" route generation support. Mostly for the sake of speed and maintainability, the new router will simply use the first matching route in your routes.rb file, rather than the "best" match. If you've been working at all on the Edge and haven't noticed the deprecation warnings, then this probably won't affect you.

Oh, so that's why!

Jay Pignata provided a patch this week to help out all of you RESTful API developers. Previously, when a client sent invalid XML or JSON to your server, Rails would 500 with an oh-so-descriptive /!\ FAILSAFE /!\ error in your logs. This wasn't much help if you were trying to debug it. So, with this patch, you'll now get to look at the raw data that was posted to your server in your logs.

Speaking of Resources

Finally, a few updates went into ActiveResource this week which will make it a lot more familiar to those of us who are more comfortable with ActiveRecord. Validation support has been added, which will allow you to both validate your resources locally - before transmission - and remotely. ActiveResource no longer throws a ResourceNotFound error when you attempt to find a set of undefined resources [Resource.find(:all)]. Instead, ActiveResource is reverting to the more ActiveRecord-like empty set/nil response. And last, but not least, resource.save! will now raise a ResourceInvalid unless the resource is, actually .. well .. valid?

That's it for this week's update on Edge Rails. I hope that you've enjoyed it.

Photo: Hood River Sunset by Bernt Rostad

Posted in Edge | 9 comments

Comments

  1. Andrew Roth on 20 Aug 17:19:

    very informative, thanks. but can you include commit links next time?

  2. Nathaniel Bibler on 20 Aug 18:14:

    @andrew Sure. I guess I just forgot to do that this week. I’ll add ‘em in real quick. Thanks. :)

  3. John on 21 Aug 03:12:

    Can I use rails3 right now for fresh simple apps with AR, jquery and rspec + cucumber?

  4. Alastair Brunton on 21 Aug 14:13:

    Thanks Nathaniel, its great to be able to keep up with the goings on whilst eating my breakfast!

  5. antivirus on 22 Aug 06:27:

    Very interessting info. Thanks for the post.

  6. Luca on 22 Aug 07:41:

    hi! Is there a release dte for rails 3?

  7. Joseph Kelly on 22 Aug 15:10:

    The :object option for render :partial is not currently deprecated in Rails 2.2 (nor 2.3?), so it doesn’t seem reasonable to remove it now. Deprecate it in Rails 3 and remove it in a later release please?

  8. lcd hdtv on 25 Aug 09:38:

    Fresh Ruby updates make my day, thank you Nathaniel ;-)

  9. UGG Classic Cardy on 12 Sep 05:45:

    Only One word to characterize such a great post “WOW” that was a very interesting read