问题在我添加rental_application_personal_details
并尝试从表中访问first_name
后开始。
控制器:
def create
unless @rental_application.submittable?
redirect_to @rental_application, notice: "You can't submit the rental application unless you complete it!"
return
end
if @rental_application.submitted!
RentalApplicationMailer.sales_agent_message(@rental_application, @rental_application_personal_details, @agent).deliver_now
if @rental_application.payment_request.authorized
CapturePaymentJob.perform_later(@rental_application.payment_request)
else
@rental_application.payment_request.void!
end
redirect_to @rental_application, notice: 'Your application was submitted! :)'
else
redirect_to @rental_application, notice: 'We were unable to submit your application.'
end
end
Rental Application Mailer:
def sales_agent_message(rental_application, rental_application_personal_details, agent)
@rental_application = rental_application
@rental_application_personal_details = rental_application_personal_details
@agent = agent
@sales_agent = @rental_application.sales_agent.email
mail(:to => @sales_agent, :subject => "New Rental Application Recieved!")
end
销售代理消息:
你好!
<%= @ rental_application_personal_details.first_name%>给你发了一份租赁申请! %GT;
查看它<%= link_to'HERE!',matrix_rental_applications_url%>
错误:
答案 0 :(得分:1)
@rental_application_personal_details
似乎永远不会被设置在任何地方。在create
方法中,您正在使用它,但您从未在第一时间给它一个值。因此,它没有。 nil.first_name
是您目前的错误。
答案 1 :(得分:0)
你可以把它写成
if @rental_application.submitted! && @rental_application_personal_details.present?
//code to send the mail
end