Rails2とルーティングの仕方が変わっているようなのでメモ。
1. public/index.htmlを消しておく
mv ./app/public/index.html ./app/public/index.html.backup
2.ルーティングの設定
./config/routes.rbを編集する。
上に書くほど優先順位が高くなる。
ルートコントローラの設定
以下のように設定すると、labelsコントローラのnewアクション画面がデフォルトページとなる。
config/routes.rb
root :to => 'labels#index'
Scaffoldを利用した場合
resourcesが追記される。
Rails2のmap.resourcesであり、自動でCRUDに沿ったルーティングルールを作成してくれるので便利。
これの下にmatchルールを書いても、こちらが優先されるので注意。
config/routes.rb
resources :labels
matchを使った設定
matchルールで様々なパターンのルーティングができる。
例えば以下のように書くと、http://〜/feedbackというURLでは、feedbacksコントローラのnewアクションを表示する。
それ以外はpagesコントローラを参照する。
config/routes.rb
match "feedback" => 'feedbacks#new'
match "pages(/:action)" => 'pages#:action'
match "(:action)" => 'pages#:action'