good day!
I have an application mailer and I want to call the application record to put it on the mailer. Is it possible to do this?
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 is the Application record that I want to call.
It should work but you should get a specific template, right now you are getting an ActiveRecord::Relation
change EmailTemplate.where(category_id: 1)
to
EmailTemplate.where(category_id: 1).first
or EmailTemplate.find_by(category_id: 1)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.