method
find
v3.1.0 -
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.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