0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ActionMailerでdefault_url_optionを使って環境毎にURLを変更する

Posted at

config/environments/**.rb

に環境毎のホスト名を指定して使いたくて調べた。

以下を設定すれば良いとあったのだけど、
config.action_mailer.default_url_options = { host: 'develop.com' }

設定後、どうすればURLが取れるかわからなかった..

しばらく以下の意味がわからなかったけど..
https://railsguides.jp/action_mailer_basics.html#action-mailer%E3%81%AE%E3%83%93%E3%83%A5%E3%83%BC%E3%81%A7url%E3%82%92%E7%94%9F%E6%88%90%E3%81%99%E3%82%8B

routesの普段pathの所をurlに変更して引数を指定すれば、URLを返してくれる。

こんなroutesの設定があったら

activate GET    /registrations/:id/activate(.:format)     registrations#activate

以下のようにcontroller ,viewで指定すればdefault_url_optionsを反映したURLが取れる

activate_url(@user.activation_token) 

ふいー

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?