RAILS 如何在 ApplicationMailer 中调用 ApplicationRecord?

How to call ApplicationRecord in ApplicationMailer on RAILS?

美好的一天!

我有一个应用程序邮寄器,我想调用应用程序记录将其放在邮寄器上。可以这样做吗?

class UserMailer < ApplicationMailer
  def verification_email
    @user = params[:user]
    @token = @user.verification_token

    email_template = EmailTemplate.where(category_id: 1)
    @subject = email_template.subject
    @greetings = email_template.greetings
    @content = email_template.content
    @closing = email_template.closing

    mail(to: @user.email, subject: @subject)
  end
end

EmailTemplate 是我要调用的应用程序记录。

它应该可以工作,但您应该得到一个特定的模板,现在您得到的是 ActiveRecord::Relation

改变EmailTemplate.where(category_id: 1)

EmailTemplate.where(category_id: 1).firstEmailTemplate.find_by(category_id: 1)