All threads / Attaching file to email Active Storage

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Attaching file to email Active Storage

Stephen Sizer asked in Rails

Hi Guys,

I am trying to attach a pdf to an email via active storage. Here is my code below and the error I am getting.

class Assignment < ApplicationRecord
has_one_attached :upload
belongs_to :user
belongs_to :course
belongs_to :lesson

after_save :send_notifications

def send_notifications
AssignmentMailer.notify_user(user).deliver_later
AssignmentMailer.notify_team(user, upload).deliver_later
end
end

ERROR:
No such file or directory @ rb_sysopen - /rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBFQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--889c8cda6fbfb3c827ff5bcd7a4ca7ff1594a37e/weekend.pdf

Thanks,
Steve

Are using the correct url? So instead of blabla_path use blabla_url?

Changed to _url and not get this error:

Unsupported argument type: ActiveStorage::Attached::One
Extracted source (around line #35):

def send_notifications
AssignmentMailer.notify_user(user).deliver_later
-- AssignmentMailer.notify_team(user, upload).deliver_later ---
end
end

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 33,399+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.