2017-07-22 90 views
0

我有一個agent模型和agent_card模型。一旦有人正在僱用代理卡,爲他們創建。我試圖讓一個郵件發送一次該人被僱用,但不知道爲什麼它不工作。任何幫助表示讚賞。問題Rails梅勒沒有射擊

代理控制器 - 採用方法:

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: "[email protected]" 

    def agent_card_message(agent_card, agent) 
    @agent_card = agent_card 
    @agent = agent 

    mail(:to => "[email protected]", :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} 

回答

0

在視圖中,我沒有打電話給代理。

它需要的是:一個星期六... amirite

Name: <%= @agent.agent_card.agent.name %><br><br> 
Date Created: <%= @agent.agent_card.created_at.strftime("%m/%d/%Y @ %l:%M %p") %> 

編程?