Flowdock
method

find

Importance_2
v3.2.13 - Show latest stable - 0 notes - Class: ActiveResource::Base
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.json

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

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

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

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

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

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

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

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

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

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.