Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matt-stj/ae2aeac711b883918eeb to your computer and use it in GitHub Desktop.
Save matt-stj/ae2aeac711b883918eeb 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?

It's the doorman to your app a.k.a. --> it handles all incoming requests and routes them to the correct place, controller, etc.

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

get "/items" => "items#index"

get "/items/:id" => "items#show"

get "/items/new" => "items#new"

post "/items" => "items#create"

get "/items/:id/edit" => "items#edit"

put "/items/:id" => "items#update"

delete "/items/:id" => "items#destroy"

  1. What does root :to => "items#index" represent? How would you access that route in a web app?

It sets the root url of the application - which is usually where you land when you first first visit the page. You could access it from the web by going to url for that page (i.e. www.itemapp.com) and you'd be taken to a page that shows all items.

  1. What rake task is useful when looking at routes, and what information does it give you?

'$ rake routes' -> because it shows you all of the known routes for your applicaiton and where each one points to.

  1. How would you interpret this output: items GET /items(.:format) items#index

Fetch me the items route for an incoming GET request to see all items, where a file extension isn't requred for the end of the route.

  1. What is one major similiarity between Rails routing + controllers and the Sinatra projects we've been building?

We structure with an MVC architecture, and we'll be using the same on Rails.

  1. What is one major difference between Rails routing + controllers and the Sinatra projects we've been building?

Rails has pre-built in methods to carry out controller actions, so we don't have to explicitly build them.

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