Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GregoryArmstrong/2b34a8dc0c9a7702d24c to your computer and use it in GitHub Desktop.
Save GregoryArmstrong/2b34a8dc0c9a7702d24c to your computer and use it in GitHub Desktop.
CRUD in Sinatra -- Check for Understanding
  1. Define CRUD.

    • Create, Read, Update, Delete. Describes the type of actions one should be able to do to the database.
  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.

      1. See all: '/tasks' + GET
      1. See one: '/tasks/:id' + GET
      1. Form to create (part 1): '/tasks/new' + GET
      1. Create from form (part 2): '/tasks' + POST
      1. Form to update (part 1): '/tasks/:id/edit' + GET
      1. Update from form (part 2): '/tasks/:id' + PUT
      1. Delete one: '/tasks/:id' + DELETE
  3. Why do we use set method_override: true?

    • Modern browsers have not agreed upon a way to use PUT or DELETE yet. As a result, we have to use a few creative solutions to be able to use these other 2 verbs, and they use method_override to do it.
  4. Explain the difference between value and name in this line: <input type='text' name='task[title]' value="<%= @task.title %>"/>.

    • I believe that in this instance the 'name' is being used to denote by what name the data being input will be referred to, while the 'value' is what that data actually is.
  5. What are params? Where do they come from?

    • Params are the data input by the user, they come from the form fields provided in the app.
@rwarbelow
Copy link

Looks good!
#4: value is what will be displayed in the html to the user
#5: params can also come from the URL

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