【问题标题】:How to call an ApplicationHelper method in Mailer with Ruby on Rails 6如何使用 Ruby on Rails 6 在 Mailer 中调用 ApplicationHelper 方法
【发布时间】: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 添加到我的邮件程序会建立必要的连接,不是吗?

【问题讨论】:

标签: ruby-on-rails ruby helper ruby-on-rails-6 mailer


【解决方案1】:

成功了

include ApplicationHelper

而不是

helper :application

【讨论】:

    猜你喜欢
    • 2020-05-17
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 2016-11-04
    相关资源
    最近更新 更多