My rails app have two servers and the urls are:
- staging.subdomain.example.com
- subdomain.example.com
And my routes look like:
['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
However, when I uses the url helpers, I meet a problem. It always returns the staging
url.
For example, on production:
course_url(132, host: "subdomain.example.com")
=> "http://staging.subdomain.example.com/courses/132"
I think the reason is that in the routes, the url helpers are only generated for staging
constraint, not the other one.
$ rate routes
...
courses GET /courses(.:format) subdomain/courses#index {:subdomain=>"staging.subdomain"}
GET /courses(.:format) subdomain/courses#index {:subdomain=>"subdomain"}
...
Does anyone have a good solution?
Cheers