Rails routes match full hostname with multiple period in between

时光毁灭记忆、已成空白 提交于 2019-12-11 07:54:22

问题


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 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 ?


回答1:


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


来源:https://stackoverflow.com/questions/6065955/rails-routes-match-full-hostname-with-multiple-period-in-between

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!