Ricardo Furgeson
2006-Jul-20 17:53 UTC
[Rails] 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 -- Posted via http://www.ruby-forum.com/.
James Ludlow
2006-Jul-20 18:14 UTC
[Rails] Newbie question-----Downloading a file and sending it to DB
On 7/20/06, Ricardo Furgeson <ricardo.orozco@hp.com> wrote:> 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).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
Ricardo Furgeson
2006-Jul-20 21:32 UTC
[Rails] Re: Newbie question-----Downloading a file and sending it to
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? -- Posted via http://www.ruby-forum.com/.
James Ludlow
2006-Jul-20 21:42 UTC
[Rails] Re: Newbie question-----Downloading a file and sending it to
On 7/20/06, Ricardo Furgeson <ricardo.orozco@hp.com> 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