2017-08-31 6 views
0

メーラーをレールにセットして、実際に配信されるメッセージ以外はすべて正常に動作しています。私は送信されている電子メールの中のデータベースからデータをレンダリングしようとしています。私は、メソッドのエラーを取得し続ける。ここで私が持っているものです。Rails 5 Mailer noメソッドエラー

contact_recieved.html.erbはここ

<td valign="top"> 
    <h2 style="color: #0f060f; font-size: 22px; text-align: center;"><%[email protected]%></h2> 
    <p style="color: #0f060f; font-size: 14px; line-height: 22px; text-align: center;">Name: <%[email protected]%></p> 

    <p style="color: #0f060f; font-size: 14px; line-height: 22px; text-align: center;">Email: <%[email protected]%></p> 
    <p style="color: #0f060f; font-size: 14px; line-height: 22px; text-align: center;">Message: <%[email protected]%></p> 
    </td> 

は私contact_controller.rbです:

class ContactsController < ApplicationController 
    def new 
    @contact = Contact.new 

    end 
    def show 
    @contact = Contact.find(params[:id]) 
    end 

    def create 
    # fail 
    @contact = Contact.create(contact_params) 
    if @contact.save 
     ContactMailer.contact_received(@contact).deliver 
     redirect_back(fallback_location: root_path) 
    else 
     flash[:error] = @contact.errors.full_messages 
     redirect_back(fallback_location: root_path) 
    end 


    end 
    private 
    def contact_params 
    params.require(:contact).permit(:name, :subject, :email, :message) 
    end 
end 

そして最後に、ここでは私のcontact.rbモデルです:

class Contact < ApplicationRecord 
    email_regex = /\A([\w+\-].?)[email protected][a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i 

    validates :name, :presence => true, 
       :length   => { :maximum => 50 } 
    validates :subject, :presence => true, 
       :length   => { :maximum => 50 } 
    validates :email, :presence => true, 
       :format   => {:with => email_regex } 
    validates :message, :presence => true, 
       :length   => { :maximum => 5000 } 

end 

私はフォームを提出すると、ノーメライトエラーが発生します。下記の画像を参照してください。

error message

私はそれを送信したときにデータが下に明らかなように、データベースに格納されつつある。

second image

ここcontact_mailer.rb

class ContactMailer < ApplicationMailer 
    default from: "[email protected]***********" 



    def contact_received(contact) 

    mail(to: "*******.com", subject: "This is just a test from Jay") 
    end 
end 

UPDATE

です

私は@contactする@contactsを変更し、私はまだ同じエラーメッセージを取得しています:

third error

+0

ください 'ContactMailer'クラス – rony36

答えて

0

更新あなたのメーラークラスが変数(@contact = contact)を割り当てること。

class ContactMailer < ApplicationMailer 
    default from: "[email protected]***********" 



    def contact_received(contact) 
    @contact = contact 

    mail(to: "*******.com", subject: "This is just a test from Jay") 
    end 
end 
+0

のいくつかのいくつかのコードは、私は、私はちょうどそれを特定することができませんでした何かを忘れて知っていたので、ありがとうございました。 –