久保清隆のブログ

ライフハック、健康、旅行など、役立つ情報を書きます。

Ruby on RailsでwebサイトのURL表示をかっこよく方法

例えば、
http://abc.ne.jp/hoge/fuga/foo/indexというURLを、
http://abc.ne.jp/hogeにしたい場合、

config/routes.rbで

ActionController::Routing::Routes.draw do |map|

  map.connect 'hoge',:controller => "hoge/fuga/foo",:action => "index"

  # Allow downloading Web Service WSDL as a file with an extension
  # instead of a file named 'wsdl'
  map.connect ':controller/service.wsdl', :action => 'wsdl'

  # Install the default route as the lowest priority.
  map.connect ':controller/:action/:id.:format'
  map.connect ':controller/:action/:id'
end

と記述すればよい。