Ruby 邮件程序:参数数量错误
Ruby Mailer: Wrong number of arguments
我正在构建我的邮件程序,但我将 运行 保存到:
wrong number of arguments (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
其他人能看到大海捞针吗?还是我完全漏掉了其他东西?
如果重要的话,我将使用邮戳进行投递,并根据文档在我的 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'
mail ...
行在SendLink.rb
看起来不对,改成,
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
结束
我有一个类似的问题,我将我的 ActionMailer 方法命名为 "message" 结果它是 Rails 中的保留字并抛出错误。
我假设 "mail" 是保留字,而 "email" 不是。
我正在构建我的邮件程序,但我将 运行 保存到:
wrong number of arguments (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
其他人能看到大海捞针吗?还是我完全漏掉了其他东西?
如果重要的话,我将使用邮戳进行投递,并根据文档在我的 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'
mail ...
行在SendLink.rb
看起来不对,改成,
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
结束
我有一个类似的问题,我将我的 ActionMailer 方法命名为 "message" 结果它是 Rails 中的保留字并抛出错误。
我假设 "mail" 是保留字,而 "email" 不是。