rails mailer和rake任务问题

时间:2021-04-30 18:12:48

If an agent hasn't been verified, I want one email to be generated and sent to me with all of their names. Not sure where I went wrong.

如果代理商尚未经过验证,我希望生成一封电子邮件并将其发送给我,并附上所有姓名。不知道我哪里出错了。

agent_card_mailer.rb

agent_card_mailer.rb

class AgentCardMailer < ActionMailer::Base
  default from: "Help <help@email.com>"

  def not_verified_message(agent_card)
    @agent_card = agent_card

    mail(:to => "me@email.com", :subject => "Agent License Issues")
  end
end

not_verified_message.html.erb

not_verified_message.html.erb

Hi there,<br><br>

These agents have not been verified.<br><br>

<% @agent_cards.each do |agent_card| %>
  <%= agent_card.agent.name %><br>
<% end %>

issue_with_license.rake

issue_with_license.rake

namespace :agent_cards do
  desc 'Send out weekly email for agents with issues'
  task remind_license_issues: :environment do
    AgentCard.all.each do |agent_card|
      if agent_card.verified == false
        AgentCardMailer.not_verified_message(agent_card).deliver_now
      end
    end
  end
end

error:

错误:

ActionView::Template::Error: undefined method `each' for nil:NilClass

1 个解决方案

#1


1  

Your mailer is setting the attribute @agent_card but the template is looking for the plural @agent_cards

您的邮件程序正在设置属性@agent_card,但模板正在查找复数@agent_cards

#1


1  

Your mailer is setting the attribute @agent_card but the template is looking for the plural @agent_cards

您的邮件程序正在设置属性@agent_card,但模板正在查找复数@agent_cards