回答

1

如果您想要實現的是您發送的電子郵件中的URL是使用當前的主機或域構造的,則default_url_options方法將不起作用,因爲它只在應用程序啓動時設置一次 - 請求對象不是在這種情況下可用AFAIK,但只能在控制器操作中使用。

你可以嘗試去生成在郵件類的電子郵件,網址,不使用默認的主機,這樣的事情(未測試):

class Mailer < ActionMailer::Base 

    def welcome(user, host) 
    @url = url_for(host: host, controller: ..., action: ...) 
    # construct rest of email here 
    end 

end 

,然後從你的控制器與相應的主機叫它要求:

Mailer.welcome(current_user, request.host).deliver