Forum: Ruby on Rails Attach CSV String as attachment

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fd0b8a5e3854d056ee30f07feedf2219?d=identicon&s=25 Mario Gr (mario517)
on 2009-04-09 21:30
I am trying to take a csv string output and send it as a file
attachment, but keep my data is only coming out as gobbly gook.  The csv
string is valid going into the mailer action.

Valid CSV

   id,name,dealer_code,created_at,quantity,total_quote,shipping_cost
   1000012,Testing project,,Thu Apr 09 16:31:08 UTC 2009,0,0,0.0
   1000013,test,,Thu Apr 09 16:35:19 UTC 2009,0,0,0.0


In Action Mailer, I have:

  def report(csv, name)
    .
    .
    .
    body :name => name
    attachment "text/csv; charset=utf-8" do |a|
      a.body = csv
      a.filename = name
    end
  end


unfortunately, this gives me:

   --mimepart_49de4abf9b848_6d414263a4194
   Content-Type: text/csv; name="New projects"
   Content-Transfer-Encoding: Base64
   Content-Disposition: attachment; filename="New projects"

   aWQsbmFtZSxkZWFsZXJfY29kZSxjcmVhdGVkX2F0LHF1YW50aXR5LHRvdGFs
   X3F1b3RlLHNoaXBwaW5nX2Nvc3QKMTAwMDAxMixUZXN0aW5nIHByb2plY3Qs
   LFRodSBBcHIgMDkgMTY6MzE6MDggVVRDIDIwMDksMCwwLDAuMAoxMDAwMDEz
   LHRlc3QsLFRodSBBcHIgMDkgMTY6MzU6MTkgVVRDIDIwMDksMCwwLDAuMAo=
This topic is locked and can not be replied to.