Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Automatic365/d618bb0c2b3404011354444d1cff0387 to your computer and use it in GitHub Desktop.
Save Automatic365/d618bb0c2b3404011354444d1cff0387 to your computer and use it in GitHub Desktop.
Intro to Rails Routing Warm-Up Questions
  1. What is the purpose of the router in a Rails project?
  • The Router looks at the HTTP verb (GET, POST, PUT, DELETE) and the URL that it being requested and matches it with the appropriate controller action to run.

2.What routes would be provided to you with the line resources :items?

  • All of the RESTful routes:
  • GET all the posts (aka "index" the posts)
  • GET just one specific post (aka "show" that post)
  • GET the page that lets you create a new post (aka view the "new" post page)
  • POST the data you just filled out for a new post back to the server so it can create that post (aka "create" the post)
  • GET the page that lets you edit an existing post (aka view the "edit" post page)
  • PUT the data you just filled out to edit the post back to the server so it can actually perform the update (aka "update" the post)
  • DELETE one specific post by sending a delete request to the server (aka "destroy" the post)
  1. What does root :to => "items#index" represent? How would you access that route in a web app?

    • It represents where the client lands when they access the page url without any paths.
  2. What rake task is useful when looking at routes, and what information does it give you?

    • rake routes. It will output all the routes your application knows.
  3. How would you interpret this output: items GET /items(.:format) items#index

    • The incoming HTTP verb and URL are in the middle columns. The controller action they map to is on the right. The (.:format) means that it's okay but not required to specify a file extension. The "name" of the route is the leftmost column.
  4. What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?

    • It uses the same CRUD methods
  5. What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?

    • Rails requires only one line of code to access all of the RESTful routes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment