2016-08-27 9 views
0

ルビーmail_formとHeroku Sendgridを使用して私に電子メールを送信できるようにします。未定義のローカル変数またはメソッド「メール」連絡先:クラス

:私は私が私のフォームを設定しているページを訪問したときに、私は次のエラーメッセージが表示され、

class Contact < MailForm::Base 

attribute name, :validate => true 
attribute email, :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i 
attribute message, :validate => true 
attribute nickname,:captcha => true 

def headers 
{ 
    :subject => "Contact Form", 
    :to  => "[email protected]", 
    :from => %("#{name}" <#{email}>) 
} 
end 
end 

しかしアプリケーション/モデル/ contact.rbに次のContactクラスを設定していますニックネーム::私の連絡先クラスで定義された電子メール属性をコメントアウト

undefined local variable or method `email' for Contact:Class 

は、後続の属性メッセージで同様のエラーが生成さ

以下

は私の連絡先コントローラ、contacts_controller.rb

class ContactsController < ApplicationController 

def new 
    @contact = Contact.new 
end 

def create 
    @contact = Contact.new(params[:contact]) 
    @contact.request = request 
    if @contact.deliver 
    flash.now[:error] = nil 
    else 
    flash.now[:error] = "Oops! There was an error." 
    render :new 
    end 
end 

end 

と私のフォームで、new.html.erb

<% provide(:title, "Contact") %> 
<h1>Contact</h1> 
<%= form_for @contact do |f| %> 
<%= f.label :name %><br> 
<%= f.text_field :name, required: true %> 

<br> 

<%= f.label :email %><br> 
<%= f.text_field :email, required: true %> 

<br> 

<%= f.label :message %><br> 
<%= f.text_area :message, as: :text %> 

<div class="hidden"> 
<%= f.label :nickname %><br> 
<%= f.text_field :nickname, hint: "Leave this field blank." %> 
</div> 

<%= f.submit "Send Message", class: "btn" %> 
<% end %> 
<ul class="pager"> 
<li><a href="<%= blog_path %>">Previous</a></li> 
</ul> 

すべてのヘルプや提案をいただければ幸いです!

答えて

0

fromオプションで二重引用符を省略しました。

def headers 
{ 
    :subject => "Contact Form", 
    :to  => "[email protected]", 
    :from => %("#{name}" <#{email}>) 
} 
end 
関連する問題