Ask A Question


You’re not receiving notifications from this thread.

Upload image and send email without saving to the database

Lee Terng Gio asked in Rails

I recently tried to implement summernote to my rails app. I can send email and everything works fine. But I want to upload image and send the email, but the email received shows that the image was broken. How do I fix it?

The email that attached with uploaded image doesn't need to be saved into database. I just want to send the email.

My mailer.rb
def message_send(candidate_mail)
@candidate_mail = candidate_mail
to: "#{}",
from: "#{@candidate_mail.from}",
subject: "#{@candidate_mail.subject}",
body: "#{@candidate_mail.body}",
content_type: "text/html",
important: true,
inline_css: true,


FormObjects would be the way to go not save to your DB. Chris did a screencast for just this use case:

As for the image url: depends. Too little info to give a complete answer, but likely it's not a public url. See into the gem you use for file uploading for a "make public url" option.
I can send the email, the problem is the image is broken in the received email. I have seen documentation of how to add attachments to email, but that's not what I want because those are normally refer to public file or something or they hard code it. I use summernote to save the text and image, and they render properly in view, but the image shows broken when it's being sent out as an email. For your information, the image is encoded in Base 64 when save into database.
Join the discussion
Create an account Log in

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

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

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