LoginSignup
17
11

More than 5 years have passed since last update.

ActionMailerでHelperを呼び出すとエラーになる

Posted at
ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

原因

ActionMailer内で、Helperを呼び出してたから

class HogeMailer < ApplicationMailer
    def hoge(foo)
      @link = hoge_url(foo.id)
    end
end

解決

default_url_optionsのhostを指定する

config.action_mailer.default_url_options = { host: 'localhost:3000' }

hostが、xxx_urlで指定したときに、割り当てられるホスト名になる
http://[host]/

例:
http://localhost:3000/

参考

Rails/Deviseからメールを送信しようとした際のURL指定に関するエラーの解決

17
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
11