A one-time generated CSV file in RoR - ruby-on-rails

Is it possible to create a CSV file right out of the command line in IRB or elsewhere with a one-time use on it. Say, I just need a CSV file with all my user's first name on it.
Can I create that without setting up any architecture?

Yes, use Ruby's csv library (it's part of the standard lib):
http://ruby-doc.org/stdlib/libdoc/csv/rdoc/classes/CSV/Writer.html

What database are you using? It seems doubtful that you'd need to use Rails at all. For example:
How to output MySQL query results in CSV format?

Related

How do I add rows/columns to an existing xlsm file in Rails?

I have an existing .xlsm file in my application. I have to be able to edit it. I mean I want to add rows/columns to it. How do I do it? What are the possible solutions? I have just started learning Rails, so I am unfamiliar with most of the things.
You can use the rubyXL gem. It lets you edit xslx files e.g. worksheet[0][0].change_contents("", worksheet[0][0].formula)

Ruby on Rails - Testing the contents of a CSV file

So I have a link on my rails web page that generates a CSV file. How would I go about writing a functional test to test that the CSV file is created properly and check the contents of it?
There are probably many ways. Here's a version that won't make you jump through browser hoops
Extract the creation of a CSV to another non-controller class
In your controller test, assert your CreatesCSV receives the right parameters
Test your CreatesCSV class by writing its output to a file, then reading it in and verifying the hash is correct.

Rails 3.2 zip multiple text files

I need to write about 10 text files from query results then zip and send them.
Is there a way to do this all in memory or do I need to write the files to /tmp or database first? What is best practise for a Rails 3.2.11 application?
I don't need any functionality beyond creating the files, zipping and sending them in a single action. The files are not large.
You will need to create some temporary files. Where you chose to put them is up to, you, however.
Here's a blog post (not mine, and not tested, but I see no reason the process described shouldn't work) that describes using Rails to zip some files and send the resulting archive to the user. It shouldn't be too hard to adapt it for your needs.

Rails3 compatible way of exporting data into yaml and files should be individual records

https://github.com/adamwiggins/yaml_db is a good tool to dump and then to load data from yaml to tables. However it dumps all the records in one file.
I am looking for a solution which dumps data into individual files for each table name. Is there something that is Rails 3.1 compatible?
The currently maintained version of this project seems to do this.
From https://github.com/ludicast/yaml_db README:
rake db:data:dump_dir -> Dump contents of database to curr_dir_name/tablename.extension (defaults to yaml)

Prawn gem: How to create the .pdf from an *existing* file (.xls)

Can anybody show me (maybe copy/paste a simple code example) how to create the .pdf file from an existing (.xls) file, using the Prawn gem? (Basically, I'd need the command that "opens" the existing file.)
(I'm asking because the Prawn documentation (http://prawn.majesticseacreature.com/docs/) seems to be gone since quite a while - it's not even usable via Google cache...)
Thanks a lot for any help with this!
Tom
I'd suggest that you break the problem down.
Can you read xls with Ruby? Possibly, but it's flaky at best. However, you can easily read csv, and xls exports nicely to that format.
Can you write a 'table' of values to a prawn pdf? Yes
So, (almost) all you need is a little program that can parse a csv file into a prawn-friendly table-structure and then hand it off to Prawn for generation.
Turns out the Prawn gem cannot handle existing files...
Prawn can be used to render content on top of a PDF. You're talking about .xls, a completely different format.

Resources