Skip to content

Instantly share code, notes, and snippets.

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

    • Create, Read, Update, Delete
  2. 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.

    • get '/' --> Serves as the index/list of "things"
    • get '/new' --> Renders form used to create new "thing"
    • post '/' --> Creates thing and redirects to "get '/'"
    • get '/:id' --> Renders view of individual "thing"
    • get '/:id/edit' --> Renders view of form to edit "thing"
    • put '/:id' --> Updates "thing" and redirects to "get '/:id'"
    • delete '/:id' --> Deletes "thing" and redirects to "get '/'"
  3. Why do we use set method_override: true? Browsers cannot read "PUT" or "DELETE" requests. We need to override the form method to a specified value ("put" or "delete") to perform actions that update or delete.

  4. Explain the difference between value and name in this line: <input type='text' name='task[title]' value="<%= @task.title %>"/>. --> Value sets the..okay not 'physical' input per se, but it sets the actual value-to-be-submitted to whatever value is equal to. Name is the way we will refer to this piece of data on the back end.

  5. What are params? Where do they come from? --> It's a hash that stores all the parameters received with an HTTP request. They come from the http request following a ?

@rwarbelow
Copy link

Mostly good!

For #2, each of your routes should be proceeded by '/tasks' -- for example: get '/tasks/:id'
#5: params can come from either form data filled in by the user or data from the url

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