Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lingtran/db88ffbe701f4e0cb600 to your computer and use it in GitHub Desktop.
Save lingtran/db88ffbe701f4e0cb600 to your computer and use it in GitHub Desktop.
CRUD in Sinatra -- Check for Understanding
  1. Define CRUD.
  • Create. Read. Update. Delete.
  • CRUD references the types of functions/verbs that exist in a database.
  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.
  • specific to the Task Manager app...
  • read -> '/tasks' -> see all tasks, render :index view
  • read -> '/tasks/#{id}' -> see single task with specific task id, render :show view
  • create -> '/tasks/new' -> see form to input task info, render :new view
  • create -> '/tasks' -> submit task to be saved, redirect to '/tasks/#{id}' or '/tasks' (design decision)
  • update -> '/tasks/#{id}/edit' -> see form to edit task info, render :edit view
  • update -> '/tasks/#{id}' -> click subit and saved updated info, redirect to '/tasks/#{id}' or '/tasks' (design decision)
  • delete -> '/tasks/#{id}' -> delete a particular task, redirect to '/tasks'
  1. Why do we use set method_override: true?
  • This will enable overriding a method/verb that is defaulted to an element such as a form with other inputs
  1. Explain the difference between value and name in this line: <input type='text' name='task[title]' value="<%= @task.title %>"/>.
  • Information submitted through a form will be stored in a params hash. The name will be a hash key and the value will specific to the hash key specified with the task title.
  1. What are params? Where do they come from?
  • See response in question 4.
@Carmer
Copy link

Carmer commented Mar 23, 2016

name in the is what defines the key of the params hash, and value is what is actually in the input field on the document.

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