Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble adding a file stored on S3 through Paperclip as an attachment in ActionMailer
    primarykey
    data
    text
    <p>I'm using Paperclip and S3 for file upload and storage in a Rails 3 app. The uploading of the files is working well, but when trying to attach an uploaded file to an email message with actionmailer, I am running into issues. After a lot of troubleshooting, hopefully someone can offer a hint.</p> <p>From a high level, it seems like I may need to download the file first, with some kind of download method before attaching, which is suggested here but I do not quite follow on how to implement - <a href="https://stackoverflow.com/questions/4356936/paperclip-actionmailer-adding-an-attachment">paperclip + ActionMailer - Adding an attachment?</a></p> <p>In the app, after a user uploads a file (a Quiz in this case), the admin should be notified via email with the file that was uploaded by the user. I keep running into a "No such file or directory". Below is the code I am working with right now. Any ideas or suggestions would be much appreciated!</p> <pre><code>Quiz.rb model - what users are uploading: class Quiz &lt; ActiveRecord::Base attr_accessible :quiz_path, :user_id, :tutorial_id validates_presence_of :quiz_path validates_attachment_size :quiz_path, :less_than =&gt; 50.kilobytes validates_attachment_presence :quiz_path validates_attachment_content_type :quiz_path, :content_type =&gt; ["application/pdf","application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"], :message =&gt; 'We only accept Microsoft Excel files ending in .xlsx or .xls' belongs_to :user belongs_to :tutorial has_attached_file :quiz_path, :storage =&gt; :s3, :s3_permissions =&gt; :private, :path =&gt; "quizzes/:attachment/:style/:id.:extension", :storage =&gt; :s3, :s3_credentials =&gt; { :access_key_id =&gt; ENV["AWS_ACCESS_KEY_ID"], :bucket =&gt; ENV["S3_BUCKET_NAME"], :secret_access_key =&gt; ENV["AWS_SECRET_ACCESS_KEY"] } end </code></pre> <p>The AdminMailer class:</p> <pre><code> class AdminMailer &lt; ActionMailer::Base default from: "info@mydomain.com" def admin_upload_notification_email(quiz, current_user) @url = "http://mydomain.com" @quiz = quiz @user = current_user mail(to: "me@mydomain.com", :subject =&gt; "New Upload From #{@user.email}") attachments["#{quiz.quiz_path_file_name}"] = File.read("{quiz.quiz_path.expiring_url(60)}") end end </code></pre> <p>Also adding the QuizzesController:</p> <pre><code>def create @user = current_user @quiz = @user.quizzes.create(params[:quiz]) respond_to do |format| if @quiz.save UserMailer.upload_notification_email(@user).deliver AdminMailer.admin_upload_notification_email(@quiz, @user).deliver format.html { redirect_to @user, notice: 'Your skill assessment answer file was successfully uploaded. We will review your responses and email you a link to your results as soon as possible.' } format.json { render json: @user, status: :created, location: @quiz } elsif @quiz.errors.any? flash[:error] = 'Please make sure you selected your answer file and it ended in ".xlsx".' return(redirect_to :back) else format.html { redirect_to @user, notice: 'No file was selected. Please back and choose "Select Your Answer File" before submitting.' } format.json { render json: @quiz.errors, status: :unprocessable_entity } end end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload