How to Keep Format of Temporary File (How do I?)

Hi,

Alright, here is the problem. In one action, I store an array of arrays
in a temporary file, like this:

@temp_file = Tempfile.new("temporary_csv_file")
@temp_file.puts @parsed_file
@temp_file.close

By array of arrays, I mean something like this:
[["ihoih", "iuhoi", "hibib"] ,["ihdfd", "eefoi", "qwib"], ["jmjih",
"plplhoi", "recsf"]]

In another action, I try to read the file, like this (path is the path
of the file):
@stored_file = File.open(params[:path])

But I just get back a String with each value separated by \n

How can I store and retrieve an array of arrays using a temporary file?

Hi,

Alright, here is the problem. In one action, I store an array of
arrays
in a temporary file, like this:

@temp_file = Tempfile.new("temporary_csv_file")
@temp_file.puts @parsed_file
@temp_file.close

By array of arrays, I mean something like this:
[["ihoih", "iuhoi", "hibib"] ,["ihdfd", "eefoi", "qwib"], ["jmjih",
"plplhoi", "recsf"]]

In another action, I try to read the file, like this (path is the path
of the file):
@stored_file = File.open(params[:path])

But I just get back a String with each value separated by \n

How can I store and retrieve an array of arrays using a temporary
file?#

Have you looked at what happens when you do puts on an array ? Puts
isn't some magic serializer, what it's outputting to your file isn't
enough for anyone to put it back together.

You need to use something that will properly dump the structure of
your data, eg yaml or Marshal.dump

Fred

Frederick Cheung wrote:

You need to use something that will properly dump the structure of
your data, eg yaml or Marshal.dump

Fred

Thanks, I got it working. Hopefully this can help anyone else searching
with the same problem.

@temp_file = Tempfile.new("temporary_csv_file")
@temp_file.write(YAML::dump(@parsed_file))
@temp_file.close

Then to open it:
@csv_file = YAML::load(File.open(params[:path]))