我正在尝试使用 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
有谁知道发生了什么?