メーラーをレールにセットして、実際に配信されるメッセージ以外はすべて正常に動作しています。私は送信されている電子メールの中のデータベースからデータをレンダリングしようとしています。私は、メソッドのエラーを取得し続ける。ここで私が持っているものです。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
私はフォームを提出すると、ノーメライトエラーが発生します。下記の画像を参照してください。
私はそれを送信したときにデータが下に明らかなように、データベースに格納されつつある。
ここ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を変更し、私はまだ同じエラーメッセージを取得しています:
ください 'ContactMailer'クラス – rony36