-
Define CRUD. CRUD stands for C reate, R ead/Retrieve, U pdate, D elete and these refer to the four functions for working with stored information.
-
There are seven verb + path combinations that are necessary in a basic Sinatra app in order to provide full CRUD functionality. List each of the seven combinations, and explain what each is for.
- Verb: GET Path: /index See all the items that are stored (Read)
- Verb: GET Path: /item See a single item that is stored (Read)
- Verb: GET Path: /new Load a form in order to create a new item in the database (Create)
- Verb: POST Path: /index Store the item in the database (Create)
- Verb: GET Path: /item/update Load a form in order to update the attributes of an item (Update)
- Verb: PUT Path: /item Update the attributes of an item in the database (Update)
- Verb: DELETE Path: /item Delete a specific item from the database (Delete)
-
Why do we use
set method_override: true
? Form submissions in HTML only accept the methods POST and GET. In order to utilize the verbs PUT(for updating) and DELETE(for deleting), we useset method_override: true
in the app and the tags<input type="hidden" name='_method' value='put'>
with the form. -
Explain the difference between
value
andname
in this line:<input type='text' name='task[title]' value="<%= @task.title %>"/>
.name
is an internal name so that the input data can be referenced and manipulated.value
is what is displayed in the input field; this is what would be written between and opening and closing tag for a double tag, e.g. textarea. -
What are
params
? Where do they come from?params
is a hash of data that is generated from the submission of a form. This data comes from the various inputs (text, textarea, etc.) enclosed in the form.
/new
, we would see/tasks/new
./tasks/1
and a route of/tasks/:id
, we can take1
out usingparams[:id]