The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
What's New in Edge Rails: ActiveResource Finder Update and Custom Headers

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
rwdaigle

Posts: 312
Nickname: rwdaigle
Registered: Feb, 2003

Ryan is a passionate ruby developer with a strong Java background.
What's New in Edge Rails: ActiveResource Finder Update and Custom Headers Posted: May 7, 2007 7:54 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by rwdaigle.
Original Post: What's New in Edge Rails: ActiveResource Finder Update and Custom Headers
Feed Title: Ryan's Scraps
Feed URL: http://feeds.feedburner.com/RyansScraps
Feed Description: Ryan Daigle's various technically inclined rants along w/ the "What's new in Edge Rails" series.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by rwdaigle
Latest Posts From Ryan's Scraps

Advertisement

ActiveResource find Updates

The ActiveResource find method just got a little bit of tightening with a new :find option. This option basically replaces the ability to call a custom method with a single argument to find and makes find a little less open-ended.

For instance, if before you were invoking a recent custom method:


Post.find(:recent)  #=> GET /people/recent.xml

you will now need to declare the multiplicity or scope (:all in this case) as the first argument and the custom method as the :from option:


Post.find(:all, :from => :recent)  #=> GET /posts/recent.xml

You can also do the same for singleton resources with the :one scope:


Post.find(:one, :from => :latest)  #=> GET /post/latest.xml

And if you just want to manually specify the location from which to get the post, you can use the actual string URI:


Post.find(:one, :from => "/categories/1/latest.xml")  #=> GET /categories/1/latest.xml

So basically what’s happened is that the first argument to find has been tightened to allow either the resource id or the scope (:all, :first, :one) and any custom method or manual resource location has been moved to the :from option.

ActiveResource Custom Headers

ActiveResource was also recently updated to include the ability to set custom headers per resource.

1
2
3
class Post < ActiveResource::Base
  headers['X-MyHeader'] = 'ryan'
end

Every request from Post will now include that header.

Note: The original patch used custom_headers but was since changed to headers

It’s refreshing to see ActiveResource getting better and easier to use!

tags: ruby, rubyonrails, REST

Read: What's New in Edge Rails: ActiveResource Finder Update and Custom Headers

Topic: [Objects|Closures] are just a poor man's [closures|objects] Previous Topic   Next Topic Topic: Ruby: Unit testing delegations

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use