Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restful commands

I am new to RESTful stuff. But, I want to use it in my rails app. When I add this to my routes.rb map.resources :notes I get routes to these methods created:

  • index
  • create
  • new
  • edit
  • show
  • update
  • destroy

What I am wondering is what is the difference between edit/update and create/new? Is there any standard definitions of how these method pairs vary and what each one does?

like image 433
Josh Moore Avatar asked Nov 14 '08 15:11

Josh Moore


People also ask

Where are REST API commands?

Running REST commands in the command-line interface The Linux program curl is one of many programs that can run REST commands from the command line. For an example, see Running REST commands.

What is RESTful in coding?

Overview. A REST API (also known as RESTful API) is an application programming interface (API or web API) that conforms to the constraints of REST architectural style and allows for interaction with RESTful web services. REST stands for representational state transfer and was created by computer scientist Roy Fielding.


2 Answers

The standard definition is as follows:

  • index - GET - A view of all (or a selection of) the records
  • show - GET - A view of a single record
  • new - GET - A form to post to create
  • create - POST - Create a new record
  • edit - GET - A form to edit a single record
  • update - PUT - Update a record
  • destroy - DELETE - Delete a record
like image 115
Jon Wood Avatar answered Sep 25 '22 14:09

Jon Wood


When you use the scaffold generator in Rails 2 create is the action called when the form from the new action is submitted. Likewise, update is the action called when the form from the edit action is submitted.

As far as I know, you can blow that away and define them to do whatever you want depending on what create/new/edit/update means to your application.

like image 26
Owen Avatar answered Sep 24 '22 14:09

Owen