Skip to content

Instantly share code, notes, and snippets.

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

CRUD stands for Create, Read, Update, and Delete which are associated with the verbs POST, GET, UPDATE, and DELETE in HTTP.

  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.

  2. READ '/tasks' - GET a view of all tasks from index.erb

  3. READ '/tasks/:id' - GET a view of a specific task from show.erb

  4. CREATE(pt1) 'tasks/new' - GET a form to create a new task in new.erb

  5. CREATE '/tasks' - POST data to the server and redirect to '/tasks'

  6. UPDATE(pt1) '/tasks' - GET a form to input date to update an existing task from edit.erb

  7. UPDATE '/tasks/:id/edit' - PUT data to the server to update existing task information

  8. DELETE '/tasks/:id' - DELETE existing information

  9. Why do we use set method_override: true?

It allows you to use PUT and DELETE verbs in forms, since HTML requires the verb to look like POST.

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

Name defines what we will call the input(the title of our task), Value is what will be sent to the server, which in this case grabs the title of the individual task we are referring to.

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

    Params are pieces of data stored in a hash that comes from the instance variables defined in our object class. For example, in TaskManager params would include the title and description of our task, structured as a hash with a key of "task" pointing to those values.

1. Define CRUD.
CRUD stands for Create, Read, Update, and Delete which are associated with the verbs POST, GET, UPDATE, and DELETE in HTTP.
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.
1. READ '/tasks' - GET a view of all tasks from index.erb
2. READ '/tasks/:id' - GET a view of a specific task from show.erb
3. CREATE(pt1) 'tasks/new' - GET a form to create a new task in new.erb
4. CREATE '/tasks' - POST data to the server and redirect to '/tasks'
5. UPDATE(pt1) '/tasks' - GET a form to input date to update an existing task from edit.erb
6. UPDATE '/tasks/:id/edit' - PUT data to the server to update existing task information
7. DELETE '/tasks/:id' - DELETE existing information
3. Why do we use `set method_override: true`?
It allows you to use PUT and DELETE verbs in forms, since HTML requires the verb to look like POST.
4. Explain the difference between `value` and `name` in this line: `<input type='text' name='task[title]' value="<%= @task.title %>
Name defines what we will call the input(the title of our task), Value is what will be sent to the server, which in this case grabs the title of the individual task we are referring to.
5. What are `params`? Where do they come from?
Params are pieces of data stored in a hash that comes from the instance variables defined in our object class. For example, in TaskManager params would include the title and description of our task, structured as a hash with a key of "task" pointing to those values.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment