2010-12-11 13 views

答えて

3

それを渡して試してみてください:ホスト=>「yoursub.domain.com」あなたは工夫のwikiで見ることができ

+1

私は彼がそれが自動的に起こりたいと思います。 –

13

考案のwikiに説明主なソリューションは、任意の設定では動作しません。 1つのサブドメイン(またはアプリケーションのルートドメイン)のリクエスト中に電子メールの生成を開始し、電子メール内のリンクが別のサブドメインを参照するようにしたい場合は問題です。

正常に動作させるには、url_forヘルパーに:subdomainオプションを付けることです。

# app/helpers/subdomain_helper.rb 

module SubdomainHelper 
    def with_subdomain(subdomain) 
    subdomain = (subdomain || "") 
    subdomain += "." unless subdomain.empty? 
    host = Rails.application.config.action_mailer.default_url_options[:host] 
    [subdomain, host].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 

次のステップは非常に重要であると私は多くの人が(私は私がやった知っている)までのトリップを取得ところ、それはあると思います。あなたの工夫メーラーテンプレートでlink_toを行う際に工夫が今config/application.rb

config.to_prepare do 
    Devise::Mailer.class_eval do 
     helper :subdomain 
    end 
    end 

に次のコードを追加することによって、そのメーラーオブジェクトに新しいサブドメインのヘルパーをミックスしていることを確認し、簡単に:subdomainオプションを指定することができます。

link_to 'Click here to finish setting up your account on RightBonus', 
    confirmation_url(@resource, :confirmation_token => @resource.confirmation_token, :subdomain => @resource.subdomain)