在 rails 中,当路由到外部 url 并使用 _url 帮助程序时,是否可以指定默认端口号?
In rails, when routing to an external url and using the _url helper is there a way to specify the default port number?
当路由到外部 url 并使用 _url
帮助程序时,是否可以指定默认端口?
routes.rb
scope host: 'www.foo.com' do
root :to => 'dev#null', as: :marketing_site
end
当使用 _url 助手时,marketing_site_url
解析为 www.foo.com:3000
我可以使用 marketing_site_url(:port=> 80)
获得正确的 url,但我更希望端口默认为 80,但仅当将此助手用于此外部 url 时才适用。
我不确定使用 Rails 路由器是否是实现此目的的正确方法。相反,您可以为 app/helpers
中某处的站点定义 return url 的辅助方法,可能 app/helpers/marketing_site_helper.rb
.
def marketing_site_url
"http://www.foo.com"
end
当路由到外部 url 并使用 _url
帮助程序时,是否可以指定默认端口?
routes.rb
scope host: 'www.foo.com' do
root :to => 'dev#null', as: :marketing_site
end
当使用 _url 助手时,marketing_site_url
解析为 www.foo.com:3000
我可以使用 marketing_site_url(:port=> 80)
获得正确的 url,但我更希望端口默认为 80,但仅当将此助手用于此外部 url 时才适用。
我不确定使用 Rails 路由器是否是实现此目的的正确方法。相反,您可以为 app/helpers
中某处的站点定义 return url 的辅助方法,可能 app/helpers/marketing_site_helper.rb
.
def marketing_site_url
"http://www.foo.com"
end