Ich versuche, das MailForm-Juwel zu verwenden, um ein einfaches E-Mail-Formular einzurichten, aber es funktioniert nicht und nicht einmal mir irgendwelche Nachrichten.Rails MailForm Juwel funktioniert nicht
hier ist meine Controller-Methoden
class ContactsController < ApplicationController
def new
@contact = Contact.new
end
def create
@contact = Contact.new(params[:contact])
@contact.request = request
if @contact.deliver
flash.now[:notice] = "Thanks! I'll contact you soon."
else
flash.now[:error] = 'Cannot send message.'
render :new
end
end
private
def contact_params
params.require(:contact).permit(:from_email, :from_name, :subject, :message)
end
end
und dann die Ansicht (die eigentlich in der profiles/show
Seite anstelle der contact/new
Seite ist. Ist das das Problem?
<%= form_for @contact do |f| %>
<div class="form-group">
<%= f.label "Your Email" %>
<%= f.text_field :from_email, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label "Subject" %>
<%= f.text_field :subject, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label "Message" %>
<%= f.text_area :message, class: "form-control" %>
</div>
<div class="form-group">
<%= f.hidden_field :to_email, value: @user.email %>
<%= f.submit "Contact", class: 'btn btn-primary form-control' %>
</div>
<% end %>
Ich denke auch, es könnte Ein Konfigurationsproblem: Hier ist die Konfiguration, die ich für gmail
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: '<email>',
password: '<password>',
authentication: 'plain',
enable_starttls_auto: true }
verwende
Und hier ist das Modell
class Contact < MailForm::Base
# belongs_to :user
attribute :to_email
attribute :name, :validate => true
attribute :from_email, :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
attribute :subject
attribute :message
def headers
{
subject: subject,
to: to_email,
from: <email>
}
end
end
ich jede Antwort nur über versucht habe ich auf Stack-Überlauf finden kann, aber nichts funktioniert. Was mache ich hier falsch?
Können Sie mir zeigen Sie Ihre Form wie dieser https://github.com/plataformatec/mail_form#description – Nathan
@TanNguyenNhat ich die Frage nur aktualisiert –
Entschuldigung Ich habe so lange gebraucht, ich war nicht in der Stadt: p –