<bill-4qJMilvFZdi/7u6bA4Lga2Xnswh1EIUO@public.gmane.org>
2005-Aug-30 05:31 UTC
array to DB??
Can someone help a newbie here. Trying to learn Ruby and rails at the same time is troublesome. I tried looking for this in the pick axe and rails books and could find an answer to my problem. Can someone help a newbie here? I have an array called @labelArr that has n number of elements and I want to add each element of the array to a table called Labels that has two fields (id & labelName) can someone help me with how I would do this? thanks, -bill
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 bill-4qJMilvFZdi/7u6bA4Lga2Xnswh1EIUO@public.gmane.org wrote: | Can someone help a newbie here. Trying to learn Ruby and rails at the same time is troublesome. I tried looking for this in the pick axe and rails books and could find an answer to my problem. | Can someone help a newbie here? | I have an array called @labelArr that has n number of elements and I want to add each element of the array to a table called Labels that has two fields (id & labelName) can someone help me with how I would do this? If I''m reading your question right, then this should do it: @labelArr.each do |label| ~ Label.new(label).create end Assuming, of course, that the Label model is accessible and you do some proper error handling. Regs, Derek - -- Derek Wyatt - C++ / Ruby / Unix Programmer http://derekwyatt.org -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (MingW32) iD8DBQFDFZWxwwHFeC88e2IRApsyAJ93vzzHnwODxfrOxsFlqi28ik48YACfdw/C deXMsThviHQU7AdQBif1Dmc=p+EC -----END PGP SIGNATURE-----
bill-4qJMilvFZdi/7u6bA4Lga2Xnswh1EIUO@public.gmane.org wrote:> Can someone help a newbie here. Trying to learn Ruby and rails at the same time is troublesome. I tried looking for this in the pick axe and rails books and could find an answer to my problem. > Can someone help a newbie here? > I have an array called @labelArr that has n number of elements and I want to add each element of the array to a table called Labels that has two fields (id & labelName) can someone help me with how I would do this?Labels.create( @labelArr.map { |label_name| { :labelName => label_name } } ) -- We develop, watch us RoR, in numbers too big to ignore.