代码之家  ›  专栏  ›  技术社区  ›  sameera207

从轨道2到轨道3的路线更改

  •  0
  • sameera207  · 技术社区  · 14 年前

    我的Rails 2.x应用程序中有这条路线

    map.with_options(:controller => "web_page") do |site|
        site.connect "*url", :action => "index"
    end
    

    它将根目录后的每个命名空间定向到名为“web_page”的控制器和名为“index”的操作

    例如,如果输入i http://localhost:3000/products 它转到 http://localhost:3000/web_pages/index

    如果我打字 http://localhost:3000/services 但它仍然 http://localhost:3000/web_页/index

    但是在3号轨道上我该怎么做呢?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Sinetris    14 年前

    您可以使用:

    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