Skip to content

Instantly share code, notes, and snippets.

@bethsebian
Forked from rwarbelow/cfu_crud_in_sinatra.markdown
Last active December 2, 2015 20:21
Show Gist options
  • Save bethsebian/f1d5e1d8faec9d003b71 to your computer and use it in GitHub Desktop.
Save bethsebian/f1d5e1d8faec9d003b71 to your computer and use it in GitHub Desktop.
CRUD in Sinatra -- Check for Understanding
  1. Define CRUD.
    CRUD defines the four features an app that interacts with a database should have: 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 '/tasks' - displays (reads) all existing tasks in database
    • get '/tasks/new' - provides form for inputting new task (create)
    • post '/tasks' - submits data for new task (create)
    • get '/tasks/:id' - displays (reads) data from one task
    • get '/tasks/:id/edit' - provides form for editing existing task (update)
    • put '/tasks/:id' - submits data for revising existing task (update)
    • delete '/tasks/:id' - removes task (delete)
  3. Why do we use set method_override: true?
    Allows us to pass in hidden methods that are repackaged as instructions for completing update and delete methods.

  4. Explain the difference between value and name in this line: <input type='text' name='task[title]' value="<%= @task.title %>"/>.
    NAME defines syntax/variable/method for referring to the data after form is submitted.
    VALUE is content used to prepopulate the form.

  5. What are params? Where do they come from?
    Params are hashes of data created when a task is created. They are referenced to define instance variables for each task.

@rwarbelow
Copy link

Looks good! Just a few comments:

For #3, the methods are put and delete (instead of update and delete)
#4: "name" refers to what the key will be as the form data comes in through the params
#5: params contains any data that is being passed through a form or through a URL

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