【发布时间】:2023-03-26 01:41:01
【问题描述】:
我一直在尝试实现这个问题的代码:Send an email manually of a specific page in rails app
唯一的区别是我需要从我的模型中获取电子邮件地址。这在从模型发送电子邮件时通常没有问题。
UserMailer.report(self).deliver
但我想在我的记录的显示视图中单击一个按钮。
我需要使用电子邮件中记录的详细信息手动发送电子邮件。
也许有比为此使用额外的控制器更好的方法?
# app/mailers/user_mailer.rb
class UserMailer < ActionMailer
def report(thing)
@thing = thing
mail :to => thing.email, :from => 'you@example.com',
:subject => 'that report you want'
end
end
# app/views/user_mailer/report.html.erb
<h1>Report</h1>
<p>Here is your <% @thing.customer_id %></p>
# app/controllers/reports_controller.rb
def create
UserMailer.report(@thing).deliver
flash[:notice] = 'report sent!'
redirect_to root_path # or wherever
end
# in a view
<% form_tag(reports_path(@thing), :method => :post) do %>
<% submit_tag 'send report email' %>
<% end %>
我用上面的代码返回 null:
ArgumentError (wrong number of arguments (0 for 1)):
app/controllers/reports_controller.rb:3:in `create'
【问题讨论】:
标签: ruby-on-rails ruby email