08. Routes - max-borisov/ihub-bookshelf GitHub Wiki

The Rails router recognizes URLs and dispatches them to a controller's action.

Update the config/routes.rb file

Rails.application.routes.draw do
  root 'books#index'
  resources :users, only: [:show, :destroy]
  resources :books do
    resources :reviews, on: :member
  end
  resources :shopping_cart_items, only: [:index, :create, :destroy]
  resources :orders, only: [:index, :create, :destroy]  
end

The routes file may containe comments so you can leave them if you want.

Now we can get the list of all possible routes for the application. And only these routes will be served.

Open terminal window and type:

$ rake routes

And you will get smth. like that:

App routes

Here is an example of some routes we can use in app:

  • root_path
  • books_url
  • orders_path
  • edit_book_url

Helpful links