根据this guide on using custom mailers,我正在尝试覆盖设计的邮件。
# config/initializers/devise.rb
config.mailer = "AccountsMailer"
真的,我想为所有邮件操作动态设置主机。但目前,似乎只是对该reset_password_instructions
方法的基本覆盖甚至不起作用。
# app/mailers/accounts_mailer.rb
class AccountsMailer < Devise::Mailer
# allow use of before_filter
include AbstractController::Callbacks
def default_url_options
{ host: 'overridden.com' }
end
def reset_password_instructions(record, opts={})
raise 'overridden'
@host = 'overridden.co'
super
end
end
这让我怀疑设计是否甚至使用我的自定义邮件。
# views/customers/mailer/reset_password_instructions.html.erb
<% puts "*Mail View*" %>
<% puts @host %>
<% puts Devise.mailer %>
...
发送此消息时,从我的 forman 日志中:
mailer.1 | *Mail View*
mailer.1 |
mailer.1 | AccountsMailer
mailer.1 | Render customers/mailer/reset_password_instructions.html.erb
因此,Devise 声称正在使用 AccountsMailer,但方法覆盖不起作用,因为发送消息而不是引发异常,...
相关设置
- 导轨 3.2.13
- 红宝石 1.9.3-p374
- 设计 2.1.2
- 设计异步 0.5.1
- Sidekiq 2.12.0
- 工头 0.61.0
- 网络:捆绑执行独角兽 -p $PORT -c ./config/unicorn.rb
- 数据库:postgres -D /usr/local/var/postgres
- redis: redis-server /usr/local/etc/redis.conf
- 邮件捕手:邮件捕手 -f
- worker: bundle exec sidekiq -q high,2 -q default -e development -c 1
- 邮件程序: bundle exec sidekiq -q mailer -e development -c 1
免责声明
- 是的,我重新启动了工头/我的服务器
- 我不能静态设置
action_mailer.default_url_options[:host]
inenvironments/<env>.rb
,因为主机名是根据用户类型动态设置的(员工和客户有不同的子域)action_mailer.default_url_options
还不接受 proc 或 block
- 在每个视图中设置主机名太湿了,我睡不好觉
SO 搜索似乎没有看到其他人有这个问题,也没有设计 GH 问题——所以我忽略了什么?谢谢!