Routing change from Rails 2 to Rails 3
I had this route in my Rails 2.x app
map.with_options(:controller => "web_page") do |site|
site.connect "*url", :action => "index"
end
which directed every namespace after my root to a controller called 'web_page' and to an action called 'index'
For example, if a I type http://localhost:3000/products it goes to http://localhost:3000/web_pages/index
If I type http://localhost:开发者_JAVA技巧3000/services still it goes to http://localhost:3000/web_pages/index
But how can I do this in Rails 3 routes?
You can use:
match '/:all' => 'web_page#index', :constraints => { :all => /.+/ }
request to http://example.com/this/is/a/test?option=true become:
class WebPageController < ApplicationController
def index
@all = params[:all] # "this/is/a/test"
@path = request.path # "/this/is/a/test"
@query = request.query_parameters # {"option"=>"true"}
end
end
精彩评论