Я беру код из поддомена RailsCast
module UrlHelper
def with_subdomain(subdomain)
subdomain = (subdomain || "")
subdomain += "." unless subdomain.empty?
[subdomain, request.domain, request.port_string].join
end
def url_for(options = nil)
if options.kind_of?(Hash) && options.has_key?(:subdomain)
options[:host] = with_subdomain(options.delete(:subdomain))
end
super
end
end
class ApplicationController < ActionController::Base
include UrlHelper
end
Можно использовать модифицированные url_for
в представлениях контроллеров. Но у меня проблемы с ActionMailer.
Я попытался использовать следующее:
class Notifier < ActionMailer::Base
include UrlHelper
end
Но представления ActionMailer по-прежнему используют старый немодифицированный url_for из ActionDispatch::Routing::RouteSet.
Как лучше всего добавить новый url_for