我有一個自定義rake任務,我正在使用此任務的郵件程序。我有一個包含代理信息的代理表。我還有一個agent_card表,其中包含所有許可證數據。 agent_card表還具有agent_id列以標識哪個卡與哪個代理程序一起使用。當試圖運行rake任務併發送郵件時,我不斷收到「ActionView :: Template :: Error:undefined method'name'for nil:NilClass。」我無法弄清楚如何通過agent_card表獲取姓名,電子郵件和電話。我已經包含了下面的所有代碼。謝謝,麻煩您了!Rake任務w/ActionMailer - 未定義方法錯誤
錯誤:
rake aborted!
ActionView::Template::Error: undefined method `name' for nil:NilClass
/Users/michaelwiesenhart/Code/app/views/license_expire_mailer/license_expi re_mgr.html.erb:7:in `_app_views_license_expire_mailer_license_expire_mgr_html_erb___944550213720770297_70323524541360'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/template.rb:145:in `block in render'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/activesupport-4.2.6/lib/active_support/notifications.rb:166:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/template.rb:333:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/template.rb:143:in `render'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `block in instrument'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:52:in `render_template'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:14:in `render'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/renderer/renderer.rb:46:in `render_template'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/renderer/renderer.rb:27:in `render'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/rendering.rb:100:in `_render_template'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/rendering.rb:83:in `render_to_body'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionpack-4.2.6/lib/abstract_controller/rendering.rb:25:in `render'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:904:in `block in collect_responses'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:918:in `each'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:918:in `each_template'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:900:in `collect_responses'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:829:in `mail'
/Users/michaelwiesenhart/Code/app/mailers/license_expire_mailer.rb:14:in `license_expire_mgr'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionpack-4.2.6/lib/abstract_controller/base.rb:198:in `process_action'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionpack-4.2.6/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:88:in `__run_callbacks__'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionpack-4.2.6/lib/abstract_controller/callbacks.rb:19:in `process_action'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionpack-4.2.6/lib/abstract_controller/base.rb:137:in `process'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionview-4.2.6/lib/action_view/rendering.rb:30:in `process'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:596:in `block in process'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `block in instrument'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:593:in `process'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:584:in `initialize'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionmailer-4.2.6/lib/action_mailer/message_delivery.rb:25:in `new'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionmailer-4.2.6/lib/action_mailer/message_delivery.rb:25:in `__getobj__'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionmailer-4.2.6/lib/action_mailer/message_delivery.rb:34:in `message'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/actionmailer-4.2.6/lib/action_mailer/message_delivery.rb:85:in `deliver_now'
/Users/michaelwiesenhart/Code/lib/tasks/license_expiration.rake:17:in `block (3 levels) in <top (required)>'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:46:in `each'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:46:in `each'
/Users/michaelwiesenhart/Code/lib/tasks/license_expiration.rake:15:in `block (2 levels) in <top (required)>'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in `eval'
/Users/michaelwiesenhart/.rvm/gems/[email protected]/bin/ruby_executable_hooks:15:in `<main>'
代理型號:
has_one :agent_card
AgentCard型號:
belongs_to :agent
license_expire_mgr.html.erb
Hiya, <br><br>
The agent listed below has a license that will expire one week from today. Please make sure they renew before it expires!<br><br>
<strong>Name:</strong> <%= @agent.name %><br>
<strong>Phone:</strong> <%= @agent.phone %><br>
<strong>Email:</strong> <%= @agent.email %><br><br>
license_expire_mailer.rb
class LicenseExpireMailer < ActionMailer::Base
default from: "Mike <[email protected]>"
def license_expire_mgr(agent_card, agent)
@agent_cards = agent_card
@agent = agent
mail to: "[email protected]", subject: "Agent License Expiring"
end
end
我不知道爲什麼它是零。有一個與agent_card關聯的代理。我放棄了從備份恢復的數據庫。我不知道。 –
您必須檢查代理的價值,在這種情況下必須爲零。 –
@BlalaKhan我想這就是我問的問題......我該怎麼做? –