加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 21:34:21 所属栏目:百科 来源:网络整理
导读:在我的routes.rb文件中,我想在rails3中使用子域约束功能,但是我想从catch all路径中排除某些域.我不想在特定的子域中使用某个控制器.这样做的最佳做法是什么. # this subdomain i dont want all of the catch all routesconstraints :subdomain = "signup" d
在我的routes.rb文件中,我想在rails3中使用子域约束功能,但是我想从catch all路径中排除某些域.我不想在特定的子域中使用某个控制器.这样做的最佳做法是什么.
# this subdomain i dont want all of the catch all routes
constraints :subdomain => "signup" do
  resources :users
end

# here I want to catch all but exclude the "signup" subdomain
constraints :subdomain => /.+/ do
  resources :cars
  resources :stations
end

解决方法

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

试试这个Rubular

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读