We're reading the value from the database, but the `ApplicationMailer.default` method is evaluated when the application is started. So if we don't use a Proc, we'll need to restart the server every time we change the value in the database, or else the old value will still be used. Using a Proc makes sure the mailer from address is evaluated at runtime, so emails are sent using the from address currently defined in the database. The same situation took place using the devise mailer. Now we don't need to check for the settings table being present because the Proc in the devise initializer won't be evaluated before the settings table is created and populated.
7 lines
206 B
Ruby
7 lines
206 B
Ruby
class ApplicationMailer < ActionMailer::Base
|
|
helper :settings
|
|
helper :application
|
|
default from: Proc.new { "#{Setting["mailer_from_name"]} <#{Setting["mailer_from_address"]}>" }
|
|
layout "mailer"
|
|
end
|