Skip to content

Instantly share code, notes, and snippets.

@SteveOscar
Forked from rwarbelow/cfu_crud_in_sinatra.markdown
Last active December 2, 2015 16:12
Show Gist options
  • Save SteveOscar/4a5b969ba3ce8e915eb9 to your computer and use it in GitHub Desktop.
Save SteveOscar/4a5b969ba3ce8e915eb9 to your computer and use it in GitHub Desktop.
CRUD in Sinatra -- Check for Understanding

. Define CRUD.

An acrnym for Create, Read, Update, Delete, refering to database operations.

. 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.

-DELETE '/items/:id' -- used to delete a specific row from the database.
-PUT '/items/:id' -- used to update a row in the database.
-GET '/items/:id/edit' -- looks up the item to be updated.
-GET '/items/:id' -- used to read from a row in the database.
-POST '/items' -- used to add new information to the database.
-GET '/items' -- used to read all items in the database.
-GET '/items/new' -- part 1 of creating a new item, this combo does not interact with the database.

. Why do we use set method_override: true?

To enable using a verb other than GET and POST.

. Explain the difference between value and name in this line: <input type='text' name='task[title]' value="<%= @task.title %>"/>.

'value' will pre-fill the field with data, used in a CRUD sense when editing an existing row. 'name' refers to the name of the field.

. What are params? Where do they come from?

'params' come from the the path in the request, they are treated as a hash.

@rwarbelow
Copy link

Looks good!

For #5: params can come from either the path (URL) or form data submitted by the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment