Skip to content

Instantly share code, notes, and snippets.

@brianrip
Forked from rwarbelow/cfu_crud_in_sinatra.markdown
Last active February 3, 2016 00:42
Show Gist options
  • Save brianrip/b6a4a5bd6f31f5b7dea1 to your computer and use it in GitHub Desktop.
Save brianrip/b6a4a5bd6f31f5b7dea1 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/index.rb: Listing all instances
  • GET/show.rb: Shows one instance
  • GET/new.rb: Creates ability for new instance
  • POST/index.rb: Creates and saves a new instance
  • GET(update)/new.rb: Update existing instance
  • PUT/index.rb: Updates and saves edited instance
  • DELETE/index.rb: Deletes existing instance

3. Why do we use set method_override: true?

  • Because HTML does not recognize some verbs such as Put/Delete so we must override defaults with our own methods

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

  • value is what is displayed and name is the key to reference the value

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

  • params are endpoints that come from a get request. They are in the form of a ?key=value.
@rwarbelow
Copy link

  1. 👍
  2. For the paths, we're referring to the actual url path, not the view template. So for example: GET '/tasks' or PUT '/tasks/:id'
  3. 👍
  4. 👍 and we can reference this key in the params hash (for example: params[:task]
  5. That's one way params come in. They can also come from form data (like the example above) or from dynamic URL parameters: in '/tasks/:id/edit', :id would be a dynamic parameter that we can access using params[:id]

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