Here after called the controller.rb, one file(chart.png) will save in my rails app folder, so how to take this and will attach with mail?
controller.rb
def mail
@imageURL = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=5&choe=UTF-8"
open(@imageURL) do |chart|
File.open('chart.png', 'wb') {|f| f.write chart.read }
end
UserMailer.welcome_email(@imageURL, @mailID).deliver
end
how can i pass that image into welcome_email method for attaching with the mail? need some help to solve this?
user_mailer.rb
def welcome_email(imageURL, mailID)
mail(:to => mailID,
:subject => "code",
:body => "Code for the branch "+imageURL+"")
end
end
If you want to attach it to the email, you’d have to download the image, and then attach it from the file-system.
Creating attachment is easy :
If I were you, I’d just add the image in an image_tag in the body of the email
Edit : I didn’t see you were already writing the file.
So here is the complete solution :