今回次のような形でプロジェクト内にコントローラー、ビューが配置されている。
proto_project
proto_project
/app
/controllers
/prototypes
latest_controller.rb
ranking_controller.rb
/views
/prototypes
/latest
index.html.haml
/ranking
変更前
routes.rb
Rails.application.routes.draw do
namespace :prototypes do
resources :ranking, only: [:index]
resources :latest, only: [:index]
end
end
develop環境にてlocalhost:3000/にアクセスした時にlatest#indexアクションを起動するようにしたい。次の様に書くことでルーティングを設定する。
変更後
routes.rb
Rails.application.routes.draw do
root to: 'prototypes/latest#index'
namespace :prototypes do
resources :ranking ,only: [:index]
end
end
ここで次のように/controllers/prototypes/latest_controller.rbと階層があるので上記のコードのようにroot to: 'prototypes/latest#index'
と書くことで期待したルーティングを設定することができた。