Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8305437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:06:58+00:00 2026-06-08T18:06:58+00:00

Here after called the controller.rb, one file(chart.png) will save in my rails app folder,

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:06:59+00:00Added an answer on June 8, 2026 at 6:06 pm

    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 :

    attachments["filename"] = File.read("/path/to/file")
    

    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 :

    def mail  
      @imageURL = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=5&choe=UTF-8"
      path_image = "/tmp/chart-#{@imageUrl.hash}.png" #Avoid filename collision
      open(@imageURL) do |chart|
         File.open(path_image, 'wb') {|f| f.write chart.read }
      end  
    UserMailer.welcome_email(@imageURL,@mailID, path_image).deliver
    File.delete(path_image)
    end
    
    def welcome_email(imageURL,mailID, path_image)
    
    attachments["charts.png"] = File.read(path_image)
    mail(:to => mailID,
       :subject => "code",
       :body => "Code for the branch "+imageURL+"")
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a strange one. After renaming a class, one of my forms began giving
I got one controller called Profile with several function such as get_user_timeline and do_upload
After adding this to the end of my display function inside app/controllers/pages_controller.php , //
So, I'm looking through a java library (JScience) after someone here thoughfully pointed me
Here is my code after modifications, things seems working fine but I am receiving
here I am trying to call overloaded constructor after some condition has met in
After a quick research here and here , the solutions didn't work for my
Here is my setup: I have modeled my application after the SportsStore in Pro
Here I need to call a javascript function first and after some time I
here's a Fusion Tables map that's broken after a search. It does everything well

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.