Rails routing with a parameter that includes slash(/)
I would like to set the routings as follows
/url/http://google.com
tourls
controller andindex
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*/ }
精彩评论