Skip to content

Instantly share code, notes, and snippets.

@jwashke
Forked from rwarbelow/cfu_crud_in_sinatra.markdown
Last active March 23, 2016 04:23
Show Gist options
  • Save jwashke/1bd31306f8f094ef7048 to your computer and use it in GitHub Desktop.
Save jwashke/1bd31306f8f094ef7048 to your computer and use it in GitHub Desktop.
CRUD in Sinatra -- Check for Understanding
1. Define CRUD.

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.
  • GET 'somethings'
    • See a list of all things
  • GET 'somethings/thingid'
    • See a specific thing
  • GET 'somethings/new'
    • See form to create new thing
  • POST 'somethings'
    • submit form to create new thing
  • GET 'somethings/thingid/edit'
    • See the form the edit a thing
  • PUT 'somethings/thingid'
    • submit form to edit a thing
  • DELETE 'somethings/thingid'
    • delete a thing
3. Why do we use set method_override: true?

forms use POST by default. But POST is used to create new information. Because we are editing information and not creating new information we want to make a PUT request. set method_override: true tells Sinatra to use Rack::MethodOverride middleware to allow use of PUT.

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

The name variable is what we will call the element when we PUT or POST it from the form. the value is what will show in the form when the page is first loaded by the client.

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

params are the information passed in POST or PUT requests, they are passed in the body of these requests from HTML forms or input.

@Carmer
Copy link

Carmer commented Mar 23, 2016

Looks good Josh. Thanks

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