Newbie question-----Downloading a file and sending it to DB

Hi everyone,

I’m new with RoR and I’m working on a project that uploads information
(keys-values) from a file into a database. Here is the situation:
Somewhere in this file there is a strin-table such as the following:

“hello” = “hello world”
“sayHIgh” = “Saying hello to the world”

I have parsed the files with a ruby script in such a way so that when I
enter a key, I get a value (sort of like a hash). Ex: if I enter the
string “hello” I get the value “hello world”.

My problem is the following:

I want import these Key-Value into my database. The keys will go under
the key column and the value will go under the value column. I’m not
sure what to do from here.

So far I know how to collect key-values from the incoming file, I have a
view that asks user for the file (a browse button).

Does anybody have any ideas on how I can aproach this?

Thank you all for your input

On 7/20/06, Ricardo F. [email protected] wrote:

My problem is the following:

I want import these Key-Value into my database. The keys will go under
the key column and the value will go under the value column. I’m not
sure what to do from here.

So far I know how to collect key-values from the incoming file, I have a
view that asks user for the file (a browse button).

Since you already have the parsing working, this should be as simple
as creating an ActiveRecord object for your table where you store
these. Then you could do something like the following.

kvp = KeyValuePair.new # Or whatever you call your model object.
kvp.key = parsed_key # “key” is whatever your key column is really
called
kvp.value = parsed_value # “value” is whatever your value column is
really called
kvp.save

– James

Hi james, thanks for you help

One more question…where should I include the code you suggested in
relations to the parsing code I wrote, and the view?

On 7/20/06, Ricardo F. [email protected] wrote:

Hi james, thanks for you help

One more question…where should I include the code you suggested in
relations to the parsing code I wrote, and the view?

I guess I assumed that you were parsing it in a controller, which is a
decent place for the code that I posted.

– James

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs