ruby-on-rails - 使用邮件和 erb gem 发送邮件
问题描述
我正在尝试使用 Mail gem 和 ERB gem 发送电子邮件,但我一直收到此错误TypeError Exception: no implicit conversion of Hash into Integer
我阅读了 Mail Gem 文档和 ERB 文档,并按照他们的说明进行操作,但它不起作用。
这是方法,email
是目的地,errors
是一个数组,其中包含可能发生的错误(如果没有任何问题,则为空)
def self.send_file(email, errors)
@errors = errors
if errors.any?
subject = 'There has been an error'
template = %(
<html>
<p>Sorry, these errors occured:</p>
<ul>
<% @errors.each do |error| %>
<li><%= error %></li>
<% end %>
</ul>
</html>
).gsub(/^ {2}/, '')
else
subject = 'Everything is okey'
template = %(
<html>
<p> Everything it's okay! </p>
</html>
).gsub(/^ {2}/, '')
end
message = ERB.new(template, trim_mode: '<%>')
@errors = errors
mail = Mail.new do
from ENV['NOTIFICATIONS_EMAIL']
to email
subject subject
html_part do
content_type 'text/html; charset=UTF-8'
body message.run(binding)
end
end
mail.deliver
end
有谁知道发生了什么?
解决方案
推荐阅读
- sql - 更新表并添加新的主索引列
- arrays - 当公式似乎在 excel 中按预期执行时,为什么数组括号不可见?
- sql - 如何检查唯一列是否尚未包含正在插入的数据,以防止错误
- python - 重新编译是否会重置模型的权重?
- python-3.x - 使用 CustomJS 更新 Bokeh 源
- mysql - MySQL:如何并排显示列名和行字段值
- google-cloud-platform - 如何在 Google Cloud AI Platform 中的 Jupyter notebook 上使用 GPU
- android - 动态recyclerView Android kotlin
- c# - 如何根据首次激活的地区将应用程序设置为默认语言
- javascript - Express GET 路由无法识别