2011-10-18 55 views
1

获取数据我有一个电子邮件动作..简单的链接:轨3邮件从形式

<%= link_to 'Send offer by mail', offer_to_mail_car_path(@car) %> 

这应该发送通知给管理员的邮件,一些客户端提供的资金具体数额这辆车。所以客户必须插入他的电子邮件和他的报价表格。这些数据不会存储在数据库中,只是用于发送电子邮件并清除。因此,现在我收到的电子邮件中包含汽车数据,姓名,图片的网址等。但是,我如何构建一个表单来显示客户电子邮件和提供的这两个字段,控制器的外观和链接本身。感谢您无价的时间。

控制器:

def offer_to_mail 
    @car = Car.find(params[:id]) 
    CarMailer.offer_to_mail(@car).deliver 
    redirect_to @car, :notice => "Offer sent." 
    end 

回答

4

我得到了答案感谢我的一个朋友。我会在这里发布解决方案,可能有些人需要这个。

汽车邮寄会做

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>