我得到了答案感謝我的一個朋友。我會在這裏發佈解決方案,可能有些人需要這個。
汽車郵寄會做
def request_by_mail(car, your_name, your_message)
@car = car
@name = your_name
@message = your_message
@url = "http://cardealer.com/cars"
# attachments["rails.png"] = File.read("#{Rails.root}/public/images/rails.png")
mail(:to => '[email protected]',
:subject => "Car details request from a client",
:date => Time.now
)
end
在cars_controller
def request_by_mail
@car = Car.find(params[:id])
mail = params[:request_by_mail][:your_mail]
message = params[:request_by_mail][:your_message]
CarMailer.request_by_mail(@car, name, message).deliver
redirect_to @car, :notice => "Request sent."
end
和圖,其中的形式將是:
<%= form_for :request_by_mail, :url => request_by_mail_car_path(@car), :html => {:method => :get} do |f| %>
<p>
<b>Your email:</b><br>
<%= f.text_field :your_name %>
</p>
<p>
<b>Details about your request:</b><br>
<%= f.text_area :your_message %>
</p>
<%= f.submit "Send details request" %>
<% end %>
現在電子郵件模板request_by_mail.html .erb
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<h3>A client has requested details about car with stock number: <%= @car.id %></h3>
<% for asset in @car.assets %>
<img alt="photos" src="http://localhost:3002<%= asset.asset.url(:thumb) %>">
<% end %>
<p><%= @name %></p>
<p><%= @message %></p>
<p>
Car link: <a href="http://localhost:3002/cars/<%= @car.id %>">Go to car</a>
</p>
</body>
</html>