我正在构建我的邮件器,但我不断遇到:
参数数错误(0 for 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
还有人能看到大海捞针吗,还是我完全错过了别的什么?
如果重要的话,我将使用邮戳进行交付,并在应用程序中定义了这些参数。根据文档。我认为这是一个更简单的事情。
编辑完整的错误:
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"不是。
SendLink.rb
中的mail ...
行看起来不对,将其更改为,
mail(
:subject => 'Hello from Postmark',
:to => @cms484.recipient ,
:from => 'info@mysite.com',
:html_body => '<strong>Hello</strong> user!.')
好的,所以我决定重写它,看-它工作。为什么或者是什么不同于以前的版本(除了方法email vs mail,当然不可能是它?),我不知道。如果你能看到它是什么请指出给我!
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
结束