路由从Rails 2更改为Rails 3

时间:2010-11-21 19:02:55

标签: ruby-on-rails-3 routing

我在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路由中执行此操作?

1 个答案:

答案 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