将电子邮件表单附加到控制器 [英] Attaching an e-mail form to a controller

查看:150
本文介绍了将电子邮件表单附加到控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将下面的链接更改为一个表单,该表单将表单的参数发布到我的控制器以发送电子邮件...当前链接有效并发送电子邮件...

I would like to change the below link into an form that posts params of the form to my controller to send an email... the current link works and sends an email...

<%= button_to 'Hello', contact_pages_path, :method => :put %>

在我的控制器中,我有:

In My controller I have:

 def contact
   Contact.contact_form.deliver
 end

我的邮件发件人:

class Contact < ActionMailer::Base
  default from: "****"
  default to: "****"

  def contact_form
    mail(:subject => "Registered")
  end


end

在我的路线中,我有:

  resources :pages do
  put :contact, :on => :collection
  end

我意识到我需要在邮件程序中创建一个正文,但是我不确定如何创建一个表单来执行此操作并将其全部传递给我.我确实考虑过要创建一个模型来做到这一点,但我认为拥有一个仅用于从表单发送电子邮件的完整模型会导致过度杀伤力吗?

I realise that I need to create a body in the mailer - but I am not sure how to create a form to do this and pass it all on. I did think about creating a model to do this, but I thought having an entire model for just sending an email from a form would be slight over kill?

推荐答案

<%= form_tag(contact_pages_path, :method => "post") do %>
  <%= text_field_tag "article", "firstname" %> 
  <%= submit_tag("Search") %>
<% end -%>

提交时,它将转到contact_pages_path,并在控制器中尝试params[:article],因此其值应为名字".

When you submit it will go to contact_pages_path and in your controller try params[:article], so its value should be "first name".

这篇关于将电子邮件表单附加到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆