Created
January 27, 2012 15:17
-
-
Save sinisterchipmunk/1689251 to your computer and use it in GitHub Desktop.
Code examples for "Understanding REST in Rails 3" - http://thoughtsincomputation.com/understanding-rest-in-rails-3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REST request | CRUD request | Action | |
----------------|----------------------|------- | |
POST /posts | /posts/create | Create | |
GET /posts/1 | /posts/show/colin | Read | |
PUT /posts/1 | /posts/update/colin | Update | |
DELETE /posts/1 | /posts/destroy/colin | Delete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/profile/posts | |
/profile/posts/new | |
/profile/posts/1 | |
/profile/posts/1/edit | |
/profile/posts/1/destroy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource :user do | |
resources :devices do | |
member do | |
put 'activate' | |
put 'deactivate' | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/user/devices | |
/user/devices/1 | |
/user/devices/1/edit | |
/user/devices/1/activate | |
/user/devices/1/deactivate | |
# and so forth. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
put 'activate', :as => 'enable' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# these are equivalent to one another | |
resources :devices, :only => [:index, :create, :update, :destroy, :show] | |
resources :devices, :except => [:new, :edit] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources :support_requests, :except => :destroy do | |
member do | |
delete 'destroy', :action => 'cancel' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE /support_requests/:id(.:format) #=> {:action=>"cancel", :controller=>"support_requests"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scope "/admin" do | |
resources :accounts | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/admin/accounts | |
/admin/accounts/new | |
/admin/accounts/1 | |
# and so forth. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scope :except => [:edit, :new] do | |
resource :profile | |
resources :posts | |
# as many as you want! | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REST request path | Rails action name | Description | |
---------------------|-------------------|------------- | |
GET /posts | index | Render a list of all post | |
GET /posts/new | new | Render a form for creating a single new post | |
POST /posts | create | Create a single new post from the received data | |
GET /posts/1 | show | Render a single existing post | |
GET /posts/1/edit | edit | Render a form for editing a single existing post | |
PUT /posts/1 | update | Update a single existing post based on the received data | |
DELETE /posts/1 | destroy | Destroy a single existing post |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/profiles/1/show |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/profile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REST request path | Rails action name | Description | |
---------------------|-------------------|------------- | |
GET /profile/new | new | Render a form for creating the profile | |
POST /profile | create | Create a the profile from the received data | |
GET /profile | show | Render a the profile | |
GET /profile/edit | edit | Render a form for editing the profile | |
PUT /profile | update | Update the profile based on the received data | |
DELETE /profile | destroy | Destroy the profile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource :profile | |
resources :posts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rake routes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource :profile do | |
resources :posts | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/profile | |
/profile/new | |
/profile/edit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment