config/routes.rb
使用環境 | |
Ruby on Rails | 2.2.2 |
map.root
map.root :controller => 'users'
root / {:action=>"index", :controller=>"users"}
map.connect
map.connect 'articles/:year/:month/:day', :controller => 'articles', :action => 'find_by_date', :year => /\d{4}/, :month => /\d{1,2}/, :day => /\d{1,2}/
/articles/:year/:month/:day {:action=>"find_by_date", :controller=>"articles"}
map.ルート名
map.new_session 'new_session', :controller => 'sessions', :action => 'new'
new_session /new_session {:action=>"new", :controller=>"sessions"}
map.with_options
map.with_options :controller => 'blog' do |blog| blog.show '', :action => 'list' blog.delete 'delete/:id', :action => 'delete' blog.edit 'edit/:id', :action => 'edit' end
show / {:action=>"list", :controller=>"blog"} delete /delete/:id {:action=>"delete", :controller=>"blog"} edit /edit/:id {:action=>"edit", :controller=>"blog"}
URLを丸ごとパラメータとして渡す
map.connect 'entry/*url', :controller => 'entry', :action => :list
/entry/:url {:action=>:list, :controller=>"entry"}
省略可能パラメータを指定する
map.connect 'for/:bar', :controller => 'foo', :action => 'show', :bar => 'default_value'
/for/:bar {:action=>"show", :controller=>"foo"}
map.resource
map.resource :com
com POST /com {:action=>"create", :controller=>"coms"} formatted_com POST /com.:format {:action=>"create", :controller=>"coms"} new_com GET /com/new {:action=>"new", :controller=>"coms"} formatted_new_com GET /com/new.:format {:action=>"new", :controller=>"coms"} edit_com GET /com/edit {:action=>"edit", :controller=>"coms"} formatted_edit_com GET /com/edit.:format {:action=>"edit", :controller=>"coms"} GET /com {:action=>"show", :controller=>"coms"} GET /com.:format {:action=>"show", :controller=>"coms"} PUT /com {:action=>"update", :controller=>"coms"} PUT /com.:format {:action=>"update", :controller=>"coms"} DELETE /com {:action=>"destroy", :controller=>"coms"} DELETE /com.:format {:action=>"destroy", :controller=>"coms"}
map.resources
参考
http://railspress.matake.jp/rails20%E3%81%AErouting%EF%BC%88configroutesrb%EF%BC%89%E3%81%AE%E8%A8%98%E8%BF%B0%E6%96%B9%E5%BC%8F%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6%E3%81%AE%E3%81%BE%E3%81%A8%E3%82%81%E3%80%82
ActiveResourceに対応したルーティングを定義する - Rails RecipeBookはてな版 - rails-recipebookグループ
複雑なルーティングを定義する - Rails RecipeBookはてな版 - rails-recipebookグループ
Routing - api.rubyonrails.org
名前の付いているものは、名前_path(new_photo_path)・名前_url(new_photo_url) を使用できる