Last Updated: February 25, 2016
·
1.372K
· matiasdim

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'

1 Response
Add your 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?

over 1 year ago ·