method
find
v3.0.9 -
Show latest stable
-
0 notes -
Class: ActiveResource::Base
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3 (0)
- 2.1.0 (1)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (7)
- 3.0.9 (-2)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
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.
-
: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