Rails 邮件程序未触发的问题
Issue with Rails Mailer not firing
我有一个 agent
模型和一个 agent_card
模型。一旦有人雇用了代理卡,就会为他们创建代理卡。一旦该人被雇用,我正试图让邮件发送,但我不确定为什么它不起作用。感谢任何帮助。
代理控制器 - 使用方法:
def employ
@agent.employee = true
@agent.on_probation = true
@agent.save(validate: false)
AgentCard.create(agent_id: @agent.id, hire_date: Date.current)
AgentCardMailer.agent_card_message(@agent_card, @agent).deliver_later
respond_to do |format|
format.html { redirect_to :back }
format.json { head :no_content }
end
end
agent_card_mailer.rb:
class AgentCardMailer < ActionMailer::Base
default from: "help@mail.com"
def agent_card_message(agent_card, agent)
@agent_card = agent_card
@agent = agent
mail(:to => "mike@mail.com", :subject => "New Agent Card Created!")
end
end
agent_card.html.erb:
Hiya Mike,<br><br>
A new Agent Card has been created!<br><br><br>
Name: <%= @agent_card.agent.name %><br><br>
Date Created: <%= @agent_card.created_at.strftime("%m/%d/%Y @ %l:%M %p") %>
错误:
2017-07-22T14:57:19.132Z 1614 TID-ox63wsdb0 WARN: {"class"=>"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", "wrapped"=>"ActionMailer::DeliveryJob", "queue"=>"mailers", "args"=>[{"job_class"=>"ActionMailer::DeliveryJob", "job_id"=>"c72ff671-6834-4274-9668-664305ff4df2", "queue_name"=>"mailers", "arguments"=>["AgentCardMailer", "agent_card_message", "deliver_now", nil, {"_aj_globalid"=>"gid://nooklyn/Agent/61967"}], "locale"=>"en"}], "retry"=>true, "jid"=>"a8ea332f8212f34f6ca1aedf", "created_at"=>1500735186.9071932, "enqueued_at"=>1500735439.0713248, "error_message"=>"undefined method `agent' for nil:NilClass", "error_class"=>"ActionView::Template::Error", "failed_at"=>1500735187.086685, "retry_count"=>4, "retried_at"=>1500735439.130213}
在视图中,我没有调用代理。
它需要是:
Name: <%= @agent.agent_card.agent.name %><br><br>
Date Created: <%= @agent.agent_card.created_at.strftime("%m/%d/%Y @ %l:%M %p") %>
星期六编程...amirite?!
我有一个 agent
模型和一个 agent_card
模型。一旦有人雇用了代理卡,就会为他们创建代理卡。一旦该人被雇用,我正试图让邮件发送,但我不确定为什么它不起作用。感谢任何帮助。
代理控制器 - 使用方法:
def employ
@agent.employee = true
@agent.on_probation = true
@agent.save(validate: false)
AgentCard.create(agent_id: @agent.id, hire_date: Date.current)
AgentCardMailer.agent_card_message(@agent_card, @agent).deliver_later
respond_to do |format|
format.html { redirect_to :back }
format.json { head :no_content }
end
end
agent_card_mailer.rb:
class AgentCardMailer < ActionMailer::Base
default from: "help@mail.com"
def agent_card_message(agent_card, agent)
@agent_card = agent_card
@agent = agent
mail(:to => "mike@mail.com", :subject => "New Agent Card Created!")
end
end
agent_card.html.erb:
Hiya Mike,<br><br>
A new Agent Card has been created!<br><br><br>
Name: <%= @agent_card.agent.name %><br><br>
Date Created: <%= @agent_card.created_at.strftime("%m/%d/%Y @ %l:%M %p") %>
错误:
2017-07-22T14:57:19.132Z 1614 TID-ox63wsdb0 WARN: {"class"=>"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper", "wrapped"=>"ActionMailer::DeliveryJob", "queue"=>"mailers", "args"=>[{"job_class"=>"ActionMailer::DeliveryJob", "job_id"=>"c72ff671-6834-4274-9668-664305ff4df2", "queue_name"=>"mailers", "arguments"=>["AgentCardMailer", "agent_card_message", "deliver_now", nil, {"_aj_globalid"=>"gid://nooklyn/Agent/61967"}], "locale"=>"en"}], "retry"=>true, "jid"=>"a8ea332f8212f34f6ca1aedf", "created_at"=>1500735186.9071932, "enqueued_at"=>1500735439.0713248, "error_message"=>"undefined method `agent' for nil:NilClass", "error_class"=>"ActionView::Template::Error", "failed_at"=>1500735187.086685, "retry_count"=>4, "retried_at"=>1500735439.130213}
在视图中,我没有调用代理。
它需要是:
Name: <%= @agent.agent_card.agent.name %><br><br>
Date Created: <%= @agent.agent_card.created_at.strftime("%m/%d/%Y @ %l:%M %p") %>
星期六编程...amirite?!