【发布时间】:2021-03-24 12:51:14
【问题描述】:
我有一个帮助函数来为用户生成电子邮件,如下所示
module ApplicationHelper
# Generate unique email for user based on their first and only cat id
def unique_email_for_user(user)
"category#{user.cats.first.id}@mywebsite.com"
end
end
我可以在我的控制器中调用这个 unique_email_for_user 函数,但不能在我的 Mailer 中调用,如下所示
class UserMailer < ApplicationMailer
# Call application_helpers
helper :application
# match the name to views/mailer/send_reminder.html.erb
def send_reminder(user)
@user = user
# Send email to user
mail(to: @user.email, reply_to: unique_email_for_user(@user), subject: "My email subject")
end
end
我得到如下错误。我认为将helper :application 添加到我的邮件程序会建立必要的连接,不是吗?
【问题讨论】:
-
这能回答你的问题吗? Access helpers from mailer?
标签: ruby-on-rails ruby helper ruby-on-rails-6 mailer