Flowdock
find(*arguments) public

Core method for finding resources. Used similarly to Active Record’s find method.

Arguments

The first argument is considered to be the scope of the query. That is, how many resources are returned from the request. It can be one of the following.

  • :one - Returns a single resource.

  • :first - Returns the first resource found.

  • :last - Returns the last resource found.

  • :all - Returns every resource that matches the request.

Options

  • :from - Sets the path or custom method that resources will be fetched from.

  • :params - Sets query and prefix (nested URL) parameters.

Examples

Person.find(1)
# => GET /people/1.xml

Person.find(:all)
# => GET /people.xml

Person.find(:all, :params => { :title => "CEO" })
# => GET /people.xml?title=CEO

Person.find(:first, :from => :managers)
# => GET /people/managers.xml

Person.find(:last, :from => :managers)
# => GET /people/managers.xml

Person.find(:all, :from => "/companies/1/people.xml")
# => GET /companies/1/people.xml

Person.find(:one, :from => :leader)
# => GET /people/leader.xml

Person.find(:all, :from => :developers, :params => { :language => 'ruby' })
# => GET /people/developers.xml?language=ruby

Person.find(:one, :from => "/companies/1/manager.xml")
# => GET /companies/1/manager.xml

StreetAddress.find(1, :params => { :person_id => 1 })
# => GET /people/1/street_addresses/1.xml

Failure or missing data

A failure to find the requested object raises a ResourceNotFound
exception if the find was called with an id.
With any other scope, find returns nil when no data is returned.

Person.find(1)
# => raises ResourceNotFound

Person.find(:all)
Person.find(:first)
Person.find(:last)
# => nil
Show source
Register or log in to add new notes.