0

知道如何将模型参数发送到邮件吗?

这就是问题所在:我有一个 cardealler 应用程序,在 car.show 页面中我创建了一个名为“发送电子邮件请求”的链接

<%= link_to 'Send email request',  send_to_mail_car_path(@car) %>

在汽车控制器中:

def send_to_mail
    CarMailer.request_email(@car).deliver
    @car = Car.find(params[:id])
    @search = Car.search(params[:search])
    redirect_to @car, :notice  => "Notification sent."
  end

这是有效的,我收到来自客户的邮件(那是我,因为它处于开发阶段的应用程序).​​. 但我收到这封邮件,只要它在这两个文件中只是纯文本:

request_email.html.erbrequest_email.text.erb

当我尝试添加一些汽车数据时,它给了我错误..所以如果我要写在这些文件中:

<%= @car.id %> 所以我可以在邮件中查看汽车的 id,而不是 id 我的屏幕上有这个错误:

Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id

4:     <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
5:   </head>
6:   <body>
7:     <h1> <%= @car.id %></h1>
8:     <p>

在 user.confirm_registration 教程中也像这样使用 <%= user.name %> 我设法在邮件中获取用户名。为什么我在我的应用程序中看不到我的车?

任何帮助将不胜感激。有些教程可能是..谢谢。

4

1 回答 1

1

问题在这里:

CarMailer.request_email(@car).deliver
@car = Car.find(params[:id])

您必须先分配给@car才能使用它。

@car = Car.find(params[:id])
CarMailer.request_email(@car).deliver
于 2011-10-18T16:42:29.583 回答