Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save theonlyrao/fd308aa6eec346b30559a3ebbd74c155 to your computer and use it in GitHub Desktop.
Save theonlyrao/fd308aa6eec346b30559a3ebbd74c155 to your computer and use it in GitHub Desktop.
Intro to Rails Routing Warm-Up Questions

What is the purpose of the router in a Rails project?

The purpose of a router in a Rails project is to determine the actions that the project performs as a result of a client accessing a particular path.

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

The full suite of RESTful actions: 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"

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

That code represents the action that the controller should rake when a user goes to the path "/". It sets the "home page" to index.

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

$ rake routes

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

That output represents thef act that when a client goes to "/items" then he will be shown the index page.

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

The first step in both Rails and Sinatra is to build CRUD functionality. Also the default paths that Rails builds are the same as the paths we have been using in our Sinatra projects.

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

Rails can build the controllers and database relationships for us. Also the paths are assigned to actions in config/routes.rb instead of in a server file.

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