Taylor Mitchell Taylor Mitchell - 5 months ago 14
Ruby Question

Paperclip files not being attached to actionmailer. No such file or directory

I am trying to attach a paperclip avatar image to an email, however it doesn't seem to realize it is an image that I am attaching, but when I place the url in my browser it finds the image. I am not sure if it is because of the random numbers that paperclip has at the end or not.

In my Usermailer

attachments.inline['avatar.jpg'] = File.read("localhost:3000#{@user.avatar.url(:medium)}")


In my email

<%= image_tag attachments['avatar.jpg'].url %>


The url it spits out is(The picture is a random stock photo for testing)

localhost:3000/system/users/avatars/000/000/026/medium/Maximus_Minimus_food_truck_Seattle_Washington.JPG?1397942965

Answer

You can use the Asset pipeline to attached the actual file path. Have not tested.

"#{Rails.root}/#{<YourAppName>::Application.assets.find_asset('avatar.jpg').pathname}"

You can find the answer here

Comments