ruby-on-rails - 是否可以在 rails mailer 的主题中使用实例或变量,以及如何使用:)
问题描述
我想在邮件主题中使用如下实例或变量。所以我想在主题中获取用户名或其他一些用户详细信息,我尝试了几件事,但每次都收到错误。我也找不到有关此的文档。
mail(:to => "test@gmail, :subject => "current_user.name") or "<%= current_user.name %>"
class PositionMailer < ActionMailer::Base
default from: "test@gmail.com"
layout 'mailer'
def general_message(position, barge_name)
@position = position
@barge_name = barge_name
mail(:to => "1234@gmail.com, :subject => "#{barge_name}")
end
end
控制器
def create
@position = Position.new(position_params)
if @position.save!
redirect_to @position
PositionMailer.general_message(@position, @barge_name).deliver
解决方案
要在引号内传递变量,您需要这样做"#{variable.value}
:subject => "#{current_user.name}"
如果它有权访问,应该这样做current_user
您必须current_user
连同位置值一起传递给邮件程序。
因此,无论您从哪里调用 add current_user
,都可能看起来像这样。
PositionMailer.general_message(position, current_user).deliver
推荐阅读
- kubernetes - Kubernetes 在所有 php-fpm pod 上执行命令
- ios - startRangingBeaconsSatisfying约束多个信标
- git - git rebase 在已经合并后到不同的分支
- r - 关于从 COVID19 WHO 数据集生成条形图的问题
- reactjs - 组件仅在包装在 `div` 中时才会更新
- php - 如何在laravel中获取选择框的多个选定值?
- machine-learning - 如何改进消费者支出调查的预测?
- java - 为什么在 Maven 中添加依赖项会触发功能?
- sql - 错误:表“p”缺少 FROM 子句条目
- html - 溢出-x:自动创建不需要的垂直滚动条