ruby-on-rails – 子域约束并排除某些子域

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 子域约束并排除某些子域前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在我的routes.rb文件中,我想在rails3中使用子域约束功能,但是我想从catch all路径中排除某些域.我不想在特定的子域中使用某个控制器.这样做的最佳做法是什么.
  1. # this subdomain i dont want all of the catch all routes
  2. constraints :subdomain => "signup" do
  3. resources :users
  4. end
  5.  
  6. # here I want to catch all but exclude the "signup" subdomain
  7. constraints :subdomain => /.+/ do
  8. resources :cars
  9. resources :stations
  10. end

解决方法

您可以在约束正则表达式中使用 negative lookahead来排除某些域.
  1. constrain :subdomain => /^(?!login|signup)(\w+)/ do
  2. resources :whatever
  3. end

试试这个Rubular

猜你在找的Ruby相关文章