A module to support custom REST methods and sub-resources, allowing you to break out of the “default” REST methods with your own custom resource requests. For example, say you use Rails to expose a REST service and configure your routes with:

   map.resources :people, :new => { :register => :post },
                          :member => { :promote => :put, :deactivate => :delete }
                          :collection => { :active => :get }

 This route set creates routes for the following HTTP requests:

   POST    /people/new/register.json # PeopleController.register
   PUT     /people/1/promote.json    # PeopleController.promote with :id => 1
   DELETE  /people/1/deactivate.json # PeopleController.deactivate with :id => 1
   GET     /people/active.json       # PeopleController.active

Using this module, Active Resource can use these custom REST methods just like the standard methods.

  class Person < ActiveResource::Base
    self.site = "http://37s.sunrise.i:3000"
  end

  Person.new(:name => 'Ryan').post(:register)  # POST /people/new/register.json
  # => { :id => 1, :name => 'Ryan' }

  Person.find(1).put(:promote, :position => 'Manager') # PUT /people/1/promote.json
  Person.find(1).delete(:deactivate) # DELETE /people/1/deactivate.json

  Person.get(:active)  # GET /people/active.json
  # => [{:id => 1, :name => 'Ryan'}, {:id => 2, :name => 'Joe'}]
Methods
D
G
O
P
Classes and Modules
Class Public methods
delete(custom_method_name, options = {})
This method is also aliased as orig_delete
    # File activeresource/lib/active_resource/custom_methods.rb, line 70
70:         def delete(custom_method_name, options = {})
71:           # Need to jump through some hoops to retain the original class 'delete' method
72:           if custom_method_name.is_a?(Symbol)
73:             connection.delete(custom_method_collection_url(custom_method_name, options), headers)
74:           else
75:             orig_delete(custom_method_name, options)
76:           end
77:         end
get(custom_method_name, options = {})

Invokes a GET to a given custom REST method. For example:

  Person.get(:active)  # GET /people/active.json
  # => [{:id => 1, :name => 'Ryan'}, {:id => 2, :name => 'Joe'}]

  Person.get(:active, :awesome => true)  # GET /people/active.json?awesome=true
  # => [{:id => 1, :name => 'Ryan'}]

Note: the objects returned from this method are not automatically converted into ActiveResource::Base instances - they are ordinary Hashes. If you are expecting ActiveResource::Base instances, use the find class method with the :from option. For example:

  Person.find(:all, :from => :active)
    # File activeresource/lib/active_resource/custom_methods.rb, line 56
56:         def get(custom_method_name, options = {})
57:           hashified = format.decode(connection.get(custom_method_collection_url(custom_method_name, options), headers).body)
58:           derooted  = Formats.remove_root(hashified)
59:           derooted.is_a?(Array) ? derooted.map { |e| Formats.remove_root(e) } : derooted
60:         end
orig_delete(custom_method_name, options = {})

Alias for delete

post(custom_method_name, options = {}, body = '')
    # File activeresource/lib/active_resource/custom_methods.rb, line 62
62:         def post(custom_method_name, options = {}, body = '')
63:           connection.post(custom_method_collection_url(custom_method_name, options), body, headers)
64:         end
put(custom_method_name, options = {}, body = '')
    # File activeresource/lib/active_resource/custom_methods.rb, line 66
66:         def put(custom_method_name, options = {}, body = '')
67:           connection.put(custom_method_collection_url(custom_method_name, options), body, headers)
68:         end
Instance Public methods
delete(method_name, options = {})
     # File activeresource/lib/active_resource/custom_methods.rb, line 105
105:     def delete(method_name, options = {})
106:       connection.delete(custom_method_element_url(method_name, options), self.class.headers)
107:     end
get(method_name, options = {})
    # File activeresource/lib/active_resource/custom_methods.rb, line 88
88:     def get(method_name, options = {})
89:       self.class.format.decode(connection.get(custom_method_element_url(method_name, options), self.class.headers).body)
90:     end
post(method_name, options = {}, body = nil)
    # File activeresource/lib/active_resource/custom_methods.rb, line 92
92:     def post(method_name, options = {}, body = nil)
93:       request_body = body.blank? ? encode : body
94:       if new?
95:         connection.post(custom_method_new_element_url(method_name, options), request_body, self.class.headers)
96:       else
97:         connection.post(custom_method_element_url(method_name, options), request_body, self.class.headers)
98:       end
99:     end
put(method_name, options = {}, body = '')
     # File activeresource/lib/active_resource/custom_methods.rb, line 101
101:     def put(method_name, options = {}, body = '')
102:       connection.put(custom_method_element_url(method_name, options), body, self.class.headers)
103:     end