Skip to content

Instantly share code, notes, and snippets.

@damwhit
Forked from rwarbelow/cfu_crud_in_sinatra.markdown
Last active February 3, 2016 20:21
Show Gist options
  • Save damwhit/d26863795cf7c1280c11 to your computer and use it in GitHub Desktop.
Save damwhit/d26863795cf7c1280c11 to your computer and use it in GitHub Desktop.
CRUD in Sinatra -- Check for Understanding
  1. Define CRUD. CRUD is an acronym that stands for create, read, update and delete. These four words correspond to the verbs in HTTP. In order to have full CRUD functionality within a Sinatral app, the app must be able to do all four of these things.
  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. i. Read '/tasks' & GET shows view of all tasks from index.erb ii. Read '/tasks/:id' & GET shows view of a specific task from show.erb iii. Create 'tasks/new' & GET makes form to create a new task in new.erb iv. Create '/tasks' & POST sends data to the server and redirect to '/tasks' v. Update '/tasks' & GET makes a form to input and update an existing task from edit.erb vi. Update '/tasks/:id/edit' & PUT sends data to the server to update existing task information vii. Delete '/tasks/:id' & Delete deletes existing information
  3. Why do we use set method_override: true? This allows us to use PUT and DELETE as they are not usually avaiable in Sinatra
  4. Explain the difference between value and name in this line: <input type='text' name='task[title]' value="<%= @task.title %>"/>. name is used to find the title value whereas value is finding the title for an instance of a task.
  5. What are params? Where do they come from? params are the name and description of a task and they come from the create method within task_manager.rb
@rwarbelow
Copy link

  1. First sentence and third sentence are correct :) the HTTP verbs are GET, POST, PUT, and DELETE
  2. Remember the leading slash on "/tasks/new". Check your routes for v. and vi.
  3. 👍 browsers don't support PUT and DELETE in forms
  4. Name is used to access the value once it comes in through params. In this specific case, we could access the value using params[:task][:title] from the controller.
  5. Data in the params hash can come from form data or through the URL.

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