所以,我已经在stackoverflow和其他地方检查了类似问题的所有现有答案,但是无法让mail_form gem像宣传的那样工作.
这是设置:我正在尝试为我公司的网站创建一个简单的潜在客户捕获表单.我希望将表单收集的数据通过电子邮件发送到我的电子邮件帐户而不需要数据库后端,我认为这就是mail_form会变得简单.
这是我的模型,ContactForm.rb:
class ContactForm < Mailform::Base attribute :name,:validate => true attribute :email,:validate => /\A([\w\.%\+\-]+)@([\w]{2,})\z/i attribute :file,:attachment => true attribute :phone attribute :referral attribute :message attribute :nickname,:captcha => true def persisted? false end def headers { :subject => "New Lead",:to => "jonthewineguy@gmail.com",:from => %("#{name}" <#{email}>) } end end
这是我的控制器,contact_forms_controller.rb:
class ContactFormsController < ApplicationController def new @contact_form = ContactForm.new end def create begin @contact_form = ContactForm.new(params[:contact_form]) @contact_form.request = request if @contact_form.deliver flash.Now[:notice] = 'Thank you for your interest!' redirect_to root_path else render :new end rescue ScriptError flash[:error] = 'Sorry,something was wrong' end end end
这是我的观点,contact_forms / new.html.erb:
<%= form_for @contact_form do |f| %> <div class="field"> <%= f.label :name %> <%= f.text_field :name,:required => true %>(required)<br /><br><br> </div> <div class="field"> <%= f.label :email %> <%= f.email_field :email,:required => true %>(required) <br /><br><br> </div> <div class="field"> <%= f.label :phone %> <%= f.phone_field :phone %><br /><br><br> </div> <div class="field"> How did you hear about us?:<br /> <%= f.text_field :referral %><br /><br><br> </div> <div class="field"> Comments (What types of wine are you interested in?):<br / <%= f.text_area :message %><br /><br><br> </div> <div class="field"> Submit: <%= f.submit "Create" %> </div> <% end %>
我对rails和Web编程一般都很陌生,所以很可能我错过了一些真正基本的东西,这在任何在线教程中都没有提到过.我已经遍历了mail_form文档以及我能找到的每个教程和答案,而且我仍然收到错误.
哦,是的!如果我在rails控制台中尝试ContactForm.new,我也会收到错误.任何帮助将不胜感激!
哦,是的,Rails版本3.1.1
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。