Hello I''m a RoR newbe facing a problem.
I would like to upload two arrays to a database called
''wrtlist'' i
used this migration file to create the database
class AddWrtsList < ActiveRecord::Migration
def self.up
create_table :wrtlist do |t|
t.string :title
t.string :link
t.string :publisher
t.timestamps
end
end
def self.down
drop_table :wrtlist
end
end
The first array contains the titles and the second contains the links,
the first title correspondents to the first title and the second to
the second....:
@titles, @links
I also want to add the static content "publisher_name" to publisher.
What should be the best way to create a loop to upload the content to
the database?
Thank you for your help!
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Got this from the ruby forum. Make a hash out of the two.
key = ["1","2","3"]
value = ["a","b","c"]
Hash[*key.zip(value).flatten]
=> {"1"=>"a", "2"=>"b",
"3"=>nil}
then you can do:
Hash.each do |key,val|
Wrtlist.create(:title => key, :link => val)
end
On Jan 25, 2:56 pm, Lasse
<lasseca...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hello I''m a RoR newbe facing a problem.
>
> I would like to upload two arrays to a database called
''wrtlist'' i
> used this migration file to create the database
>
> class AddWrtsList < ActiveRecord::Migration
> def self.up
> create_table :wrtlist do |t|
> t.string :title
> t.string :link
> t.string :publisher
>
> t.timestamps
> end
> end
>
> def self.down
> drop_table :wrtlist
> end
> end
>
> The first array contains the titles and the second contains the links,
> the first title correspondents to the first title and the second to
> the second....:
> @titles, @links
>
> I also want to add the static content "publisher_name" to
publisher.
>
> What should be the best way to create a loop to upload the content to
> the database?
>
> Thank you for your help!
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Of course, you don''t actually *need* the Hash
titles = ["1","2","3"]
links = ["a","b","c"]
titles.zip(links).each do |title, link|
Wrtlist.create(:title => title, :link => link,
:publisher => ''publisher_name'')
end
-Rob
On Jan 25, 2010, at 8:06 PM, Me wrote:
> Got this from the ruby forum. Make a hash out of the two.
>
> key = ["1","2","3"]
> value = ["a","b","c"]
> Hash[*key.zip(value).flatten]
> => {"1"=>"a", "2"=>"b",
"3"=>nil}
>
> then you can do:
>
> Hash.each do |key,val|
> Wrtlist.create(:title => key, :link => val)
> end
>
>
> On Jan 25, 2:56 pm, Lasse
<lasseca...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> Hello I''m a RoR newbe facing a problem.
>>
>> I would like to upload two arrays to a database called
''wrtlist'' i
>> used this migration file to create the database
>>
>> class AddWrtsList < ActiveRecord::Migration
>> def self.up
>> create_table :wrtlist do |t|
>> t.string :title
>> t.string :link
>> t.string :publisher
>>
>> t.timestamps
>> end
>> end
>>
>> def self.down
>> drop_table :wrtlist
>> end
>> end
>>
>> The first array contains the titles and the second contains the
>> links,
>> the first title correspondents to the first title and the second to
>> the second....:
>> @titles, @links
>>
>> I also want to add the static content "publisher_name" to
publisher.
>>
>> What should be the best way to create a loop to upload the content to
>> the database?
>>
>> Thank you for your help!
>
> --
> You received this message because you are subscribed to the Google
> Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonrails-
> talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> .
> For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
> .
>
Rob Biedenharn http://agileconsultingllc.com
Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Ya but hashes are cool, man. On Jan 25, 7:16 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> Of course, you don''t actually *need* the Hash > > titles = ["1","2","3"] > links = ["a","b","c"] > titles.zip(links).each do |title, link| > Wrtlist.create(:title => title, :link => link, > :publisher => ''publisher_name'') > end > > -Rob > > On Jan 25, 2010, at 8:06 PM, Me wrote: > > > > > Got this from the ruby forum. Make a hash out of the two. > > > key = ["1","2","3"] > > value = ["a","b","c"] > > Hash[*key.zip(value).flatten] > > => {"1"=>"a", "2"=>"b", "3"=>nil} > > > then you can do: > > > Hash.each do |key,val| > > Wrtlist.create(:title => key, :link => val) > > end > > > On Jan 25, 2:56 pm, Lasse <lasseca...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Hello I''m a RoR newbe facing a problem. > > >> I would like to upload two arrays to a database called ''wrtlist'' i > >> used this migration file to create the database > > >> class AddWrtsList < ActiveRecord::Migration > >> def self.up > >> create_table :wrtlist do |t| > >> t.string :title > >> t.string :link > >> t.string :publisher > > >> t.timestamps > >> end > >> end > > >> def self.down > >> drop_table :wrtlist > >> end > >> end > > >> The first array contains the titles and the second contains the > >> links, > >> the first title correspondents to the first title and the second to > >> the second....: > >> @titles, @links > > >> I also want to add the static content "publisher_name" to publisher. > > >> What should be the best way to create a loop to upload the content to > >> the database? > > >> Thank you for your help! > > > -- > > You received this message because you are subscribed to the Google > > Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails- > > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > . > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en > > . > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.