Skip to content

Instantly share code, notes, and snippets.

@kjs222
Forked from Carmer/crud.markdown
Last active May 10, 2016 18:25
Show Gist options
  • Select an option

  • Save kjs222/ef497180eeb81979923ec184bfbabb41 to your computer and use it in GitHub Desktop.

Select an option

Save kjs222/ef497180eeb81979923ec184bfbabb41 to your computer and use it in GitHub Desktop.
  1. Define CRUD.
  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.
  3. Why do we use set method_override: true?
  4. Explain the difference between value and name in this line: <input type='text' name='task[title]' value="<%= @task.title %>"/>.
  5. What are params? Where do they come from?
@kjs222
Copy link
Author

kjs222 commented May 10, 2016

  1. CRUD - stands for Create, Read, Update, Delete. They represent all database functions. For our purposes, they also map to HTTP verbs since web apps are essentially responding to data requests.
    • C: get - '/tasks/new' - gives user a form to enter a new task
    • C: post - '/tasks' - submits the new task
    • R: get - '/tasks' - shows all tasks to user
    • R: get '/tasks/:id' - shows one task to user
    • U: get - '/tasks/:id/edit' - gives user a form to update an existing task
    • U: put - '/tasks/:id' - submits the user's edit to the existing task
    • D: delete -'tasks/:id' - deletes an existing task
  2. By protocol, the only allowable values for the method attribute in html are get and post. If you put in a value other than the allowed values it will default to a get value. The override consists of two steps - one in the view file and one in the controller. The method_override:true in the controller allows the override in the view to take effect (?).
  3. The name parameter in the input element assigns the data submitted by that input to the associated hash key(s) of that name in the params. So, in this example, upon submission, the user input will become accessible in the params hash as params[:task][:title] . Meanwhile, the value is the existing data from the database that what will show up in the form input element on the view prior to form submission.
  4. A hash object that represents the data submitted in an HTTP request

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