サブドメイン 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 のビューは、ActionDispatch::Routing::RouteSet の古い変更されていない url_for を引き続き使用します。
新しい url_for を追加するベスト プラクティスは何ですか