2011-10-18 60 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>