Howto populate database with model data?

is there a rails way?

my brute force thinking is just put a while loop and a case statement in
the index function like this

num = 0
typenum = 0

while num < 200

when typenum
case 1
@something = Model.new
@something.whatever = 3

@something.save
case 2


case 5

end

typenum++
num++
typenum = 0 if typenum > 5

end

On Mar 29, 8:53 am, mixplate [email protected] wrote:

when typenum
end

typenum++
num++
typenum = 0 if typenum > 5

end


Posted viahttp://www.ruby-forum.com/.

You want 40 instances of 5 different types of objects, right?

[Model1,Model2,Model3,Model4,Model5].each do |model|
0.upto(40) { model.create(:whatever => 3) }
end

Is this what you’re looking for?

Jeff

awesome! but some of my models have different attributes and also i
would like to have somewhat different values for each of them. numbers i
can do a random, but not sure about the strings and text…

Jeff C. wrote:

On Mar 29, 8:53 am, mixplate [email protected] wrote:

when typenum
end

typenum++
num++
typenum = 0 if typenum > 5

end


Posted viahttp://www.ruby-forum.com/.

You want 40 instances of 5 different types of objects, right?

[Model1,Model2,Model3,Model4,Model5].each do |model|
0.upto(40) { model.create(:whatever => 3) }
end

Is this what you’re looking for?

Jeff
softiesonrails.com

You can load your test fixtures into the db using rake db:fixtures:load.

b