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

  • Home
  • SEARCH
  • 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 9210399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:04:06+00:00 2026-06-18T01:04:06+00:00

I have the below background job that writes to a csv file and emails

  • 0

I have the below background job that writes to a csv file and emails it out. I am using the Tempfile class so the file is removed after I email it to the user. Currently, when I look at the csv file I am producing the results look like the following:

["Client Application"    "Final Price"   "Tax"   "Credit"    "Base Price"    "Billed At"     "Order Guid"    "Method of Payment Guid"    "Method of Payment Type"]
["web"   nil     nil     nil     nil     nil     nil     "k32k313k1j3"   "credit card"]

Please ignore the data, but the issue is, it is being written directly to the file in the ruby format and not removing the “” and [] characters.

Please see the code below:

class ReportJob
@queue = :report_job

 def self.perform(client_app_id, current_user_id)
  user = User.find(current_user_id)
  client_application = Application.find(client_app_id)
  transactions = client_application.transactions
  file = Tempfile.open(["#{Rails.root}/tmp/", ".csv"]) do |csv|
    begin
     csv << ["Application", "Price", "Tax", "Credit", "Base Price", "Billed At", "Order ID", "Payment ID", "Payment Type"]
     transactions.each do |transaction|
      csv << "\n"
      csv << [application.name, transaction.price, transaction.tax, transaction.credit, transaction.base_price, transaction.billed_at, transaction.order_id, transaction.payment_id, transaction.payment_type]
    end
   ensure
    ReportMailer.send_rev_report(user.email, csv).deliver
    csv.close(unlink_now=false)
    end
  end
end

end

Would this be an issue with using the tempfile class instead of the csv class? or is there something I could do to change the way it is being written to the file?

Adding the code for reading the csv file in the mailer. I am currently getting a TypeError that says “can’t convert CSV into String”.

class ReportMailer < ActionMailer::Base
 default :from => "test@gmail.com"

  def send_rev_report(email, file)
     attachments['report.csv'] = File.read("#{::Rails.root.join('tmp', file)}")
      mail(:to => email, :subject => "Attached is your report")
    end
  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-18T01:04:07+00:00Added an answer on June 18, 2026 at 1:04 am

    The issue is that you’re not actually writing csv data to the file. You’re sending arrays to the filehandle. I believe you need something like:

    Tempfile.open(....) do |fh|
        csv = CSV.new(fh, ...)
        <rest of your code>
    end
    

    to properly setup the CSV output filtering.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I have a WPF UserControl (MainControl - not shown in code below) that
I have setup a resque background job that queries the slave database instead of
So I have a reporting tool that spits out job scheduling statistics in an
Let's say I have the below XML <root> <element class=Page style=background: url(/images/RlEguQY3_ghsdr.png?1324483033) repeat left
I have setup background image for a button as below. // declarations globally declared...
I have html and css as below - .title { display: block; background-color: red;
I have a page like below; <style type=text/css> #div1 { height: 100px; background-color: #CCCCCC;
I have below structure <div class=mybox> <div id=imageslide> <a href=><img src=url /></a> </div> </div>
I have below code: class Program { static void Main(string[] args) { Task[] tasks
Can the background of InkPresenter in Silverlight be transparent? So, whatever I have below

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.