【发布时间】:2018-04-04 04:26:40
【问题描述】:
我的项目中有以下工作路线:
match 'investidor/*path' => redirect('investidores/entrar'), via: :get
我还需要将其更改为重定向到不同的子域,就像在开发中这样:
match 'investidor/*path' => redirect('http://investidor.lvh.me:3000/investidores/entrar'), via: :get
此代码有效,但我需要对其进行调整以适应多种环境和多种资源,因此我不想使用if Rails.env.ENVIRONMENT? 来做到这一点,除非没有其他办法。
所以我尝试了这样的事情:
match 'investidor/*path' => redirect('investidores/entrar'), via: :get, subdomain: 'investidor'
# AND
match 'investidor/*path' => redirect('investidores/entrar'), via: :get, constraints: { subdomain: 'investidor' }
但是这两个重定向都忽略了 subdomain 参数。有什么办法吗?
谢谢!
【问题讨论】:
-
我知道您不想使用条件,但它并不像您想象的那么难看... subdomain = Rails.env.development? ? '/路径' : '/'
-
我知道,但我只是想确保没有其他方法可以做到这一点,因为我也有一个暂存环境,所以我将无法使用内联 if
标签: ruby-on-rails ruby redirect routes