Skip to content

Instantly share code, notes, and snippets.

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

CRUD stands for Create, Retrieve, Update, and Delete. These are the major functions of a database application.

  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.

Get, render index of objects Get, render data object by id Get, render form to post new data object Post, redirect to new data object (with id) Get, render form to edit an object Put/Patch, redirect to edited object by id Delete, redirect to listed tasks

(I think that this is what you're looking for?)

  1. Why do we use set method_override: true?

To allow other methods to override the post method when editing an object in the database.

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

The name is the name of the actual field used to input the title, while the value is the pre-existing variable that will be assigned to the input. I think.

  1. What are params? Where do they come from?

'params' come from the form input, and are the parameters (in this case, the title and description of the task) of the data object, stored in hash form & which can be referenced by object id.

@Carmer
Copy link

Carmer commented Mar 23, 2016

Verb+Path combos would have been more like - get + '/tasks' get + '/tasks/:id etc. We use method_override because http doesn't handle put and delete verbs - so we use the _method as the name of the hidden input field of a form so we can pass the verb through to the controller.

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