我在Rails 2.x app中有这条路线
map.with_options(:controller => "web_page") do |site|
site.connect "*url", :action => "index"
end
将我的root后面的每个命名空间定向到一个名为“web_page”的控制器和一个名为“index”的操作
例如,如果我输入http://localhost:3000/products,则会转到http://localhost:3000/web_pages/index
如果我输入http://localhost:3000/services仍然会转到http://localhost:3000/web_pages/index
但是如何在Rails 3路由中执行此操作?
答案 0 :(得分:0)
您可以使用:
match '/:all' => 'web_page#index', :constraints => { :all => /.+/ }
请求http://example.com/this/is/a/test?option=true成为:
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