これで、stackoverflowや他の場所で同様の質問に対する既存の回答をすべて確認しましたが、mail_form宝石を宣伝として機能させることはできません。レールを使用しているエラーMail_form gem: "初期化されていない定数Mailform"
私の会社のウェブサイト用の簡単なリードキャプチャフォームを作成しようとしています。私はデータベースのバックエンドなしで、フォームによって収集されたデータを自分のメールアカウントにメールしたいと思っていました。 、
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
:
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 => "[email protected]",
:from => %("#{name}" <#{email}>)
}
end
end
そして、ここでは私のコントローラ、contact_forms_controller.rb
です:ここで
は私のモデル、ContactForm.rb
ある
<%= 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 %>
私はかなり一般的なレールやWebプログラミングの新機能なので、私はmオンラインチュートリアルで言及されていない、本当にここで基本的なものを発行しています。私はmail_formのドキュメントとチュートリアルと答えが見つかっていて、まだエラーが出ています。
ああ、はい!私はまた、私がContact Console.newをレールコンソールで試してみると、エラーが出ます。どんな助けでも大歓迎です!
ああ、Railsのバージョン3.1.1
モデルファイルの名前は 'contact_form.rb'でなければなりません。それはレールの規則です。あなたはまた、エラーを言及している、あなたの質問にそれを追加することができますか? –