开发者

Rails routes match full hostname with multiple period in between

开发者 https://www.devze.com 2023-03-07 16:19 出处:网络
I\'m trying to match a URL something like http://example.com/this.is.my.full.hostname/something/else apparently when I pass the param in the routes.rb file it doesn\'t recognize this parameter

I'm trying to match a URL something like

http://example.com/this.is.my.full.hostname/something/else

apparently when I pass the param in the routes.rb file it doesn't recognize this parameter

my code says the following

match '/:computer_hostname/somethingelse' => 'test#info'

any ideas what's the right 开发者_JS百科way to achieve the URL I wanted above ? Or is it even possible ? I know period is allowed character in URL but does it allow more than one ?


I think the constraints method/option will help you out. Try something like the following:

match ':hostname/something/else' => 'test#info',
  :constraints => {:hostname => /[A-Za-z0-9\._\-]+/}

If you're doing multiple matches all with the same :hostname segment, then you can wrap them in a constraints method call:

constraints(:hostname => /[A-Za-z0-9\._\-]+/) do
  match ':hostname/something/else' => 'test#info'
  match ':hostname/foo/bar'        => 'test#foo'
end
0

精彩评论

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

关注公众号