Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save PenneyGadget/a4d2bc78fe8f1e0bead5 to your computer and use it in GitHub Desktop.
Save PenneyGadget/a4d2bc78fe8f1e0bead5 to your computer and use it in GitHub Desktop.
CRUD in Sinatra -- Check for Understanding
  1. Define CRUD.
  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.
  3. Why do we use set method_override: true?
  4. Explain the difference between value and name in this line: <input type='text' name='task[title]' value="<%= @task.title %>"/>.
  5. What are params? Where do they come from?
@PenneyGadget
Copy link
Author

  1. Create, Read, Update, Delete - the 4 basic functions of persistent storage.
  2. Using Task Manager as the example (with the understanding that it could be 'users', 'products', etc.)
    1.) GET + '/tasks' - see all our tasks
    2.) GET + '/tasks/:id - see an individual task
    3.) GET + /tasks/new' - see a form to create a new task
    4.) POST + '/tasks' - click submit and create a new task
    5.) GET + '/tasks/:id/edit' - see a form to edit an existing task
    6.) PUT + 'tasks/:id' - click update to update the edited task
    7.) DELETE + 'tasks/:id' - delete a task
  3. Because browsers don't actually understand what PUT and DELETE are. They only recognize GET and POST, meaning we have to have methods that will work around that/monkey patch and change POST into what we actually want.
  4. Not sure.. task[title] is something the server is looking for within our incoming data hash and <%= @task.title %> is accessing the title method from one of our files? Hmmmm.
  5. I think params are what is passed in after the last / in the url

@rwarbelow
Copy link

#1, #2, and #3 look good!
#4: "name" refers to what will become the key in the params hash. "value" is what will actually be displayed to the user through the browser.
#5: params can also come from data that the user enters in a form.

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