[英]Ruby Mailer: Wrong number of arguments
I'm working on building out my mailer, but I keep running into: 我正在努力建立我的邮件,但我一直在努力:
wrong number of arguments (0 for 1)
参数个数错误(0表示1)
Call my crazy, but I feel like I defined everything correctly: 叫我疯了,但我觉得我正确定义了一切:
Controller (truncated for brevity): 控制器(为简洁而截断):
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: 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
Can anybody else see the needle in the haystack or am I missing something else entirely? 任何人都能看到大海捞针还是我完全错过了其他东西?
I'm using Postmark for delivery if that matters, and have those parameters defined in my application.rb file as per the documentation. 如果重要的话,我正在使用Postmark进行交付,并根据文档在application.rb文件中定义了这些参数。 Think this is a simpler matter though.
认为这是一个更简单的问题。
Edit The complete error: 编辑完整错误:
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'
I had a similar issue where I named my ActionMailer method "message" it turns out it was a reserved word in Rails and threw an error. 我有一个类似的问题,我将我的ActionMailer方法命名为“消息”,结果发现它是Rails中的保留字并引发了错误。
I would assume that "mail" was a reserved word where "email" was not. 我认为“邮件”是一个保留字,其中“电子邮件”不是。
mail ...
line in SendLink.rb
looks wrong , change it to, SendLink.rb
mail ...
行看起来不对,将其更改为,
mail(
:subject => 'Hello from Postmark',
:to => @cms484.recipient ,
:from => 'info@mysite.com',
:html_body => '<strong>Hello</strong> user!.')
Ok, so I decided to re-write it and behold - it works. 好的,所以我决定重写它,看哪 - 它有效。 Why or what's different than the previous version(other than the method email vs mail, surely that can't be it?), I have no idea.
为什么或与以前的版本有什么不同(除了电子邮件与邮件的方法,肯定不是吗?),我不知道。 If you can see what it is, Please point it out to me!
如果你能看到它是什么, 请指出给我!
Send_link.rb: 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
Controller: 控制器:
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
end 结束
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.