Ich habe ein Formular, dass, wenn ein potenzielles mieten Interesse an der Arbeit für das Unternehmen ist, er/sie füllt es aus und fügt einen Lebenslauf. Die Einreichung wird an einen Unternehmensvertreter mit dem Anhang weitergeleitet. Die E-Mail läuft durch, aber der Anhang ist nicht das Dokument und ich kann nicht herausfinden, wie ich es richtig konfiguriere. In der Eingabe-E-Mail sagt der Anhang nur "Dokument".Büroklammer-Datei per E-Mail als Anhang senden - Rails
career_mailer.rb
class CareerMailer < ApplicationMailer
default from: "[email protected]"
def career_inquiry(career)
@career = career
attachments['attachment.extension'] = document
mail(to: "[email protected]", subject: "This is just a test from Jay")
end
end
career.rb (Modell)
class Career < ApplicationRecord
has_attached_file :document
validates_attachment_size :document, :less_than => 25.megabytes
validates_attachment_presence :document
validates_attachment_content_type :document, :content_type => ["application/pdf","application/vnd.ms-excel",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"text/plain"]
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 :phone, :presence => true,
:length => { :maximum => 50 }
validates :email, :presence => true,
:format => {:with => email_regex }
validates :message, :presence => true,
:length => { :maximum => 5000 }
end
careers_controller.rb
class CareersController < ApplicationController
def new
@career = Career.new
end
def show
@career = Career.find(params[:id])
end
def create
# fail
@career = Career.create(career_params)
if @career.save
CareerMailer.career_inquiry(@career).deliver
redirect_back(fallback_location: root_path)
else
flash[:error] = @career.errors.full_messages
redirect_back(fallback_location: root_path)
end
end
private
def career_params
params.require(:career).permit(:name, :phone, :subject, :email, :message, :document)
end
end
UPDATE
Ich versuche, die folgende in meiner Karriere Mailer:
attachments[career.document.attach_file_name] = File.read(career.document.attach.path)
ich die folgende Störung erhalte:
UPDATE 2
ich noch auf dieser arbeite, aber ich denke, basierend auf alles, was ich gelesen habe, muss ich die Büroklammer Datei vor dem Speichern in das Modell ziehen, so werde ich herausfinden, wie dies zu tun, damit ich den hochgeladenen Lebenslauf als senden kann n Anhang.