1

我的 Rails 应用程序有两台服务器,网址是:

  • staging.subdomain.example.com
  • 子域.example.com

我的路线看起来像:

  ['staging.', ''].each do |prefix|
    constraints subdomain: "#{prefix}subdomain" do
      scope module: "subdomain" do
        get "/", to: "pages#home"
        resources :courses, only: [:index, :show]
      end
    end
  end

但是,当我使用 url 助手时,我遇到了一个问题。它总是返回stagingurl。

例如,在生产中:

course_url(132, host: "subdomain.example.com")
=> "http://staging.subdomain.example.com/courses/132"

我认为原因是在路由中,url helpers 只为staging约束生成,而不是另一个。

$ rate routes
...
courses GET  /courses(.:format)  subdomain/courses#index {:subdomain=>"staging.subdomain"}
        GET  /courses(.:format)  subdomain/courses#index {:subdomain=>"subdomain"}
...

有没有人有好的解决方案?

干杯

4

0 回答 0