[英]Ruby Mailer: Wrong number of arguments
我正在努力建立我的邮件,但我一直在努力:
参数个数错误(0表示1)
叫我疯了,但我觉得我正确定义了一切:
控制器(为简洁而截断):
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
SendLink.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方法命名为“消息”,结果发现它是Rails中的保留字并引发了错误。
我认为“邮件”是一个保留字,其中“电子邮件”不是。
SendLink.rb
mail ...
行看起来不对,将其更改为,
mail(
:subject => 'Hello from Postmark',
:to => @cms484.recipient ,
:from => 'info@mysite.com',
:html_body => '<strong>Hello</strong> user!.')
好的,所以我决定重写它,看哪 - 它有效。 为什么或与以前的版本有什么不同(除了电子邮件与邮件的方法,肯定不是吗?),我不知道。 如果你能看到它是什么, 请指出给我!
Send_link.rb:
class SendLink < ApplicationMailer
def email(cms484)
@cms484 = cms484
mail(
:subject => 'Hello from Postmark',
:to => @cms484.recipient ,
:from => 'info@mysite.com',
)
end
end
控制器:
def create
@cms484 = Cms484.new(cms484_params)
respond_to do |format|
if @cms484.save
SendLink.email(@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
结束
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.