What is ActionMailer default_url_options?

I should not understand something trivial regarding email, but what does the host do in defaul_url_options? The need for smtp settings makes sense to me to configure how the email will be sent, but how does it mean default_url_options?

  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.delivery_method = :smtp
  host = '<your heroku app>.herokuapp.com'
  config.action_mailer.default_url_options = { host: host }
  ActionMailer::Base.smtp_settings = {
    :address        => 'smtp.sendgrid.net',
    :port           => '587',
    :authentication => :plain,
    :user_name      => ENV['SENDGRID_USERNAME'],
    :password       => ENV['SENDGRID_PASSWORD'],
    :domain         => 'heroku.com',
    :enable_starttls_auto => true
  }
+6
source share
2 answers

This parameter default_url_optionsis useful for building link URLs in email templates . Usually this configuration parameter is required :host, i.e. The full name of the web server. It has nothing to do with sending letters, it only adjusts the display of links in letters.

Rails Guides, ActionMailer::Base :

URL- , url_for . Action Pack, , , URL-.

url_for :host, :controller :action:

<%= url_for(host: "example.com", controller: "welcome", action: "greeting") %>

:host

<%= users_url(host: "example.com") %>

, , -, - ( ) . ( ), , .

+9

- URL- ActionMailer? , , , :

ActionView::TemplateError (Missing host to link to! Please provide :host parameter or set default_url_options[:host])

, ActionMailer , : host,: controller : action:. , ActionPack . url_for .

<%= message_url %>
<%= url_for :controller => "messages", :action => "index" %>

, URL- ActionMailer. ActionMailer, ActionMailer:

1. set a global value
2. pass the option each time you generate an URL

default_url_options , URL . .

+1

Source: https://habr.com/ru/post/1017242/


All Articles