Ich habe einen Mailer eingerichtet in Schienen funktioniert alles gut außer die eigentliche Nachricht, die geliefert werden soll. Ich versuche, Daten aus der Datenbank innerhalb der gesendeten E-Mail zu rendern. Ich bekomme immer einen Fehler ohne Methode. Hier ist, was ich habe:Rails 5 Mailer keine Methode Fehler
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>
Hier ist meine 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
Und schließlich hier ist mein contact.rb Modell:
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
Wenn ich das Formular abschicke, bekomme ich immer einen Fehler, siehe Bild unten:
Die Daten werden in der Datenbank gespeichert wurden, wenn ich es einreichen, wie unten belegt:
Hier ist die 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
Ich änderte @contacts @contact und ich bin immer noch die gleiche Fehlermeldung erhalten:
einige bitte einige Code von 'ContactMailer' Klasse – rony36