Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scottfirestone/167df90cc4f0f89984fc to your computer and use it in GitHub Desktop.
Save scottfirestone/167df90cc4f0f89984fc to your computer and use it in GitHub Desktop.
CRUD in Sinatra -- Check for Understanding
  1. Define CRUD.
  • CRUD stands for "create, read, update, delete" and refers to the main functions for manipulating stored data
  1. 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.

  2. GET /tasks - to read all tasks

  3. GET /tasks/:id - to read one task

  4. GET /tasks/new - to view form for creating new task

  5. POST /tasks - to submit form for creating new task

  6. GET /tasks/:id/edit - to view form for updating task

  7. PUT /tasks/:id - to submit form for updating task

  8. DELETE /tasks/:id - to delete a task

  9. Why do we use set method_override: true?

  • Typically browsers cannot handle DELETE and PUT requests therefore we need to use POST and override.
  1. Explain the difference between value and name in this line: <input type='text' name='task[title]' value="<%= @task.title %>"/>.
  • 'name' creates identifier for which the input's 'value' will be stored and by which the input's 'value' will be referred.
  1. What are params? Where do they come from?
  • 'params' is a hash containing info (other than method and path) sent by a client to a server. In a GET request, they are part of the path. In a POST request, they are found in the body.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment