开发者

Rails routing with a parameter that includes slash(/)

I would like to set the routings as follows

  • /url/http://google.com to urls controller and index action.

What I have now in routes.rb is开发者_C百科:

match "urls/:url" => "urls#index"

The routing doesn't seem to work because the slashed in :url.


Or you can use Route Globbing:

match "urls/*url" => "urls#index"

You can access the values in your controller via params[:url]

Reference: http://guides.rubyonrails.org/routing.html Search for "Route Globbing"


You could do something similar to

match "urls/:url" => "urls#index", :constraints => {:url => /.*/}

in Rails 2.3 which may work in Rails 3 to allow you to match the / in the :url (although, I can't test this at the moment.)


get ':klass/:id', constraints: { klass: /\D*/ }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜