Skip to content

Instantly share code, notes, and snippets.

@NickyBobby
Forked from rwarbelow/cfu_crud_in_sinatra.markdown
Last active February 3, 2016 00:38
Show Gist options
  • Select an option

  • Save NickyBobby/ea7dff3a9234554b6508 to your computer and use it in GitHub Desktop.

Select an option

Save NickyBobby/ea7dff3a9234554b6508 to your computer and use it in GitHub Desktop.
CRUD in Sinatra -- Check for Understanding
  1. CRUD stands for Create, Read, Update and Delete. These are the 4 basic functions for managing a database.

  2. So there are seven verb + path combos, the first two are Create-POST and Create-PUT. They are very similar but only difference is you use the POST method to create a new item for the database and the PUT method to modify a current item from the database. The next verb/path combo is Read-GET and this is the way you retrieve data from a webpage for viewing purposes only. The next three are Update-PUT, Update-POST and Update-PATCH. I believe the Update-PUT is modifying a current item within a database, which is also what I believe Update-POST does. Only difference is that Update-POST is for older frameworks that don't use the new PUT method yet. Next is Update-PATCH, which I believe is only a partial modification to an existing item within a database. And last is the Delete-DELETE verb/path combo and this just deletes an item altogether from within a database.

  3. The 'set method_override: true' is to over-write the POST and GET methods to use with web frames that don't have it built in.

  4. The 'value' is a predetermined value that will show up and the 'name' value will overwrite the 'value' once you hit submit.

  5. The 'params' are the parameters that are sent along with the POST or PUT methods to create or change items within a database. Actually I guess PATCH and DELETE would also have params..

@rwarbelow
Copy link

  1. 👍
  2. Your CRUD + verb combinations are correct, but take a look at this example for path + verb combinations: https://gist.github.com/ToniRib/7bf590520df2a6041c9c
  3. We can use method_override to be able to send PUT and DELETE requests even though browsers only support GET and POST.
  4. name becomes the key in the params hash. value will be its value.
  5. Params can come from form data or from the url (for example: /tasks/6/edit, we could access the 6 from params[:id])

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