2016-02-26 58 views
0

我在我的Rails應用程序中構建了一個SimpleForm,並且當我的用戶單擊「Submit」按鈕時,我想要輸入字段的數據發送到一個電子郵件地址。我會如何去做這件事?發送SimpleForm數據到電子郵件地址

<%= simple_form_for @category, :url => url_for(:action => 'bookfinal', :controller => 'users'), :method => 'post' do |f| %> 

<%= f.text_field :address1, :size=>"40", placeholder: 'Street number, street name' %> <br> 

<%= f.text_field :address2, :size=>"40", placeholder: 'Apt/Suite No' %><br> 

<%= f.text_field :citystate, :size=>"40", placeholder: 'City/State/Province' %><br> 

<%= f.text_field :country, :size=>"40", placeholder: 'Country' %><br> 

    <%= f.button :submit, 'Submit' %> 
    <% end %> 
+1

使用的ActionMailer(http://guides.rubyonrails.org/action_mailer_basics.html)發送電子郵件。要做到這一點的代碼可以放在用戶控制器的'bookfinal'動作上 – psantos

回答

0

您可以在您的操作中簡單使用ActionMailer。例如,

class UserMailer < ActionMailer::Base 
    def bookfinal(options) 
    mail(to: "[email protected]", subject: "Thanks") 
    end 
end 

class UsersController < ApplicationController 
    def bookfinal 
    # you may want to save shipping data to db first 
    UserMailer.bookfinal(params_you_want_to_pass).deliver_now 
    end 
end 

祝你好運:)

相關問題