Rails routing with a parameter that includes slash(/)

前端 未结 3 1101
遥遥无期
遥遥无期 2020-12-09 16:02

I would like to set the routings as follows

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

W

相关标签:
3条回答
  • 2020-12-09 16:29
    get ':klass/:id', constraints: { klass: /\D*/ }
    
    0 讨论(0)
  • 2020-12-09 16:47

    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"

    0 讨论(0)
  • 2020-12-09 16:49

    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.)

    0 讨论(0)
提交回复
热议问题