Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save deborahleehamel/a9e47275b9f3796ec3e16422d16a866d to your computer and use it in GitHub Desktop.
Save deborahleehamel/a9e47275b9f3796ec3e16422d16a866d 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? ..router is the doorman of your application, responds to HTTP request from user's browser so it knows which controller action/method should run
    ..acts as a matching service with your controller
    ..matches HTTP request(GET, POST, etc) to the appropriate controller action to run

  2. What routes would be provided to you with the line resources :items?
    ..this represents a handy helper method which lets you do in one line what might write in seven lines in our resources file
    ..a method shortcut which basically just outputs those seven 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)

  3. What does root :to => "items#index" represent?
    ..tells Rails which controller and action to map that route to, index will be landing page
    ..How would you access that route in a web app?
    ..through method inside the controller that is called that

  4. 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

  5. How would you interpret this output: items GET /items(.:format) items#index
    ..sends to class ItemsController and a method for index

  6. What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?
    ..matches routes (verb and path combinations)
    ..controller still talkes to model and then to database and back

  7. What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?
    ..routing and controller is separated
    ..new helper methods etc (rake routes, resources :items)
    ..business stuff is in the controller

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