1

I have am using ActionMailer to send a CSV that I am generating. The CSV content is as follows:

download_file = "Requestor Name,Job Name,Number of workers needed,Number of workers ranked,Venue,Street Address,City,State,Zip code,List of required badges,List of accepted Worker's name & email ,Job Request state,Flexible Start Time,Job Request Start Time,Job Request Max Start Time,List of Selected Date,Job Request duration,Multi-day Job,Multi-day Job ID,Number of unpaid breaks,Break minutes\nJohn Doe,Request name 1,1,,,575 Market street,San Francisco,CA,94105,\"\",\"\",posted,No,\"Jun 3 2019, 4:03pm\",,\"\",,No,,,\nJohn Doe,Request name 1,1,,,575 Market street,San Francisco,CA,94105,\"\",\"\",posted,No,\"Jun 3 2019, 4:03pm\",,\"\",,No,,,\nJohn Doe,Request name 1,1,,,575 Market street,San Francisco,CA,94105,\"\",\"\",posted,No,\"Jun 3 2019, 4:03pm\",,\"\",,No,,,\n"

I then assign it to become an attachment:

attachments["#{file_name}_#{export_time}.csv"] = download_file

I then test the content. The test fails. I see that the attachment looks like this:

"Requestor Name,Job Name,Number of workers needed,Number of workers ranked,Venue,Street Address,City,State,Zip code,List of required badges,List of accepted Worker's name & email ,Job Request state,Flexible Start Time,Job Request Start Time,Job Request Max Start Time,List of Selected Date,Job Request duration,Multi-day Job,Multi-day Job ID,Number of unpaid breaks,Break minutes\r\nJohn Doe,Request name 1,1,,,575 Market street,San Francisco,CA,94105,\"\",\"\",posted,No,\"Jun 3 2019, 4:03pm\",,\"\",,No,,,\r\nJohn Doe,Request name 1,1,,,575 Market street,San Francisco,CA,94105,\"\",\"\",posted,No,\"Jun 3 2019, 4:03pm\",,\"\",,No,,,\r\nJohn Doe,Request name 1,1,,,575 Market street,San Francisco,CA,94105,\"\",\"\",posted,No,\"Jun 3 2019, 4:03pm\",,\"\",,No,,,\r\n"

Notice that now all the \n code has been replaced with \r\n code. This occurred when upgrading from Rails 4.1 to 4.2. What is going on here?

Also, I cannot edit the attachment. The body of the attachment has a raw_source attribute but neither the body nor the raw_source are editable, so I cannot gsub it out. What can I do here to remove the new \r?

2
  • Not sure, if I missunderstood, but why should gsub not be an option. You don't have to edit the file. You load the data into a variable, do the gsub there then assign it as attachment. Why should that not work? Jun 3, 2019 at 22:53
  • Because the attachment has a body, with a raw_source, that is uneditable. I tried that. Jun 4, 2019 at 16:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.