将SimpleForm数据发送到电子邮件地址

时间:2016-02-26 16:46:02

标签: ruby-on-rails ruby ruby-on-rails-4

我正在我的Rails应用程序中构建一个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 个答案:

答案 0 :(得分:0)

您可以在行动中使用ActionMailer。例如,

class UserMailer < ActionMailer::Base
  def bookfinal(options)
    mail(to: "customer@example.com", 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
祝你好运:)