module
Ruby on Rails latest stable (v7.1.3.2)
-
0 notes
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3 (0)
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 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?
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'}]