Skip to content

Instantly share code, notes, and snippets.

@ksk5280
Forked from rwarbelow/cfu_crud_in_sinatra.markdown
Last active February 3, 2016 20:15
Show Gist options
  • Save ksk5280/c4f9d5330d7e4f2492d8 to your computer and use it in GitHub Desktop.
Save ksk5280/c4f9d5330d7e4f2492d8 to your computer and use it in GitHub Desktop.
CRUD in Sinatra -- Check for Understanding
  1. Define CRUD. Four main functions a user can use to manipulate data: Create, Read, Update, Delete
  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. Using the Task Manager example:
    1. "/tasks", GET: shows all tasks
    2. "/tasks/:id", GET: shows one task
    3. "/tasks/new", GET: shows form to create a new task
    4. "/tasks", POST: creates a new task
    5. "/tasks/:id/edit", GET: shows form to edit a task
    6. "/tasks/:id", PUT: submit form to update existing task
    7. "/tasks/:id", DELETE: deletes a task
  3. Why do we use set method_override: true? To create put and delete methods
  4. Explain the difference between value and name in this line: <input type='text' name='task[title]' value="<%= @task.title %>"/>. The value is what's put into the form, the name is a reference.
  5. What are params? Where do they come from? params is a hash that contains each task as a key with a value of another hash that contains the task title and description. It comes from the create method in task_manager.rb
@rwarbelow
Copy link

  1. 👍 in other words, four database operations
  2. 👍
  3. to use PUT and DELETE because browsers only support GET and POST in forms
  4. 👍 we can also use the name to reference the value from params: params[:name] will give us the value
  5. params can come from form data, dynamic parameters in the URL, or query strings in the URL

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