Simple and correct RESTful routing in RoR
The correct way to create routes following good practices REST (RESTful) per method are:
GET:
To obtain a users list(e.g.) the link structure should be /users and go to index action, using get
get "/users", :to =>'users#index'
And to obtain a single user(e.g.) the link structure should be /users/1 and go to show action, using get
get "/users/:id", :to =>'users#show'
POST:
To create a user(e.g.) the link structure should be /users and go to create action, using post
post "/users", :to =>'users#create'
PUT:
To update a user(e.g.) the link structure should be /users/1 and go to update action, using put
put "/users/:id", :to =>'users#update'
DELETE:
To delete a user(e.g.) the link structure should be /users/1 and go to delete action, using delete
delete "/users/:id", :to =>'users#delete'
Written by Matías
Related protips
1 Response
Thanks, very easy and illustrative. Can I ask you, if I need to execute a specific action to an entity (updating just one attribute) but without showing the user the entity we're trying to update but a couple of buttons, should I use PUT as the method for this action?