我正在构建我的邮件程序,但我一直遇到:
wrong number of arguments (0 for 1)
说我疯了,但我觉得我定义的一切都是正确的:
Controller (为简洁起见被截断):
def create
@cms484 = Cms484.new(cms484_params)
respond_to do |format|
if @cms484.save
SendLink.message(@cms484).deliver_later
format.html { redirect_to cms484s_path, notice: 'Cms484 was successfully created.' }
format.json { render :show, status: :created, location: @cms484 }
else
format.html { render :new }
format.json { render json: @cms484.errors, status: :unprocessable_entity }
end
end
发送链接.rb:
class SendLink < ApplicationMailer
def message(cms484)
@cms484 = cms484
mail(
:subject => 'Hello from Postmark',
:to => @cms484.recipient ,
:from => 'info@mysite.com',
:html_body => '<strong>Hello</strong> user!.',
end
end
其他人能看到大海捞针吗?还是我完全漏掉了其他东西?
如果重要的话,我会使用 Postmark 进行投递,并根据文档在我的 application.rb 文件中定义这些参数。认为这是一个更简单的事情。
编辑 完整错误:
Completed 500 Internal Server Error in 76ms
ArgumentError (wrong number of arguments (0 for 1)):
app/mailers/send_link.rb:2:in `message'
app/mailers/send_link.rb:4:in `message'
app/controllers/cms484s_controller.rb:38:in `block in create'
app/controllers/cms484s_controller.rb:36:in `create'
最佳答案
我有一个类似的问题,我将我的 ActionMailer 方法命名为“message”,结果发现它是 Rails 中的保留字并引发了错误。
我假设“mail”是保留字,而“email”不是。
关于 ruby 邮件程序 : Wrong number of arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30610626/