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}"
문제
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
해결책
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}"
다른 팁
Here's my model looks like
class Petition < ApplicationRecord
has_attached_file :contract
end
In mailer, I attached this contract file like this. Hope this helps.
def send_invitation(petition)
attachments[petition.contract_file_name] = File.read(petition.contract.path)
mail(
to: @petition.email,
subject: t('mailer.send_invitation')) do |format|
format.html { render 'send_invitation' }
end
I think you are supposed to use
attachments.inline['avatar.jpg'] = @user.avatar.data