Skip to content

Instantly share code, notes, and snippets.

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

*Create, Read, Update, Delete

  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.

get + "/something" renders and lists all, usually in a index view; get + "/something/:id" renders an item at a time; get + "/something/new" renders a viewable form for input; post + "/something" allows an input to be submitted, and then this is redirected to a index; get + "/something/:id/edit" allows for a form to be updated from an existing task put + "/something/:id" allows to submit an updated task; delete + "/something/:id" destroy a selected input.

  1. Why do we use set method_override: true?

*This is a sinatra method that allows the user to override an element/ process of there application. In order to allow the user to use override the user must use a _method in the link

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

*name is the id of the input field that is provided when we submit something, value is what is populated in the input field. It ends up creating a key/value pair example being task[name or title] = value(task.title)

  1. What are params? Where do they come from?
  • params are hashes that come in from the url depending on the verb used. Example would be forms and inputs
@Carmer
Copy link

Carmer commented Mar 23, 2016

we use method_override because http doesn't handle put and delete verbs - so we use the _method as the name of the hidden input field of a form so we can pass the verb through to the controller.

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