Forum: Ruby on Rails Generate a couple hundred rows of dummy data - how?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
450046d5f684ae5001c0b1a079d447d4?d=identicon&s=25 Sean Schertell (df-sean)
on 2005-12-08 15:35
Simple task -- I've done some custom pagination and I need to fill up a
table with a bunch of rows so I can play around with the back and next
buttons.  Is there an easy way from the command line perhaps to just
fire off a couple hundred copies of an existing table row?  Thanks!
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 joevandyk (Guest)
on 2005-12-08 15:48
(Received via mailing list)
On 12/8/05, Sean Schertell <sean@datafly.net> wrote:
> Simple task -- I've done some custom pagination and I need to fill up a
> table with a bunch of rows so I can play around with the back and next
> buttons.  Is there an easy way from the command line perhaps to just
> fire off a couple hundred copies of an existing table row?  Thanks!

Fire up script/console

1000.times do
  Article.create :body => 'Article body text', whatever else here
end

Should create a thousand articles for you.
2ccb2f7699267d258faaafce4ee997df?d=identicon&s=25 codyfauser (Guest)
on 2005-12-08 15:52
(Received via mailing list)
Sean,

I'd use script/console.  Example:

i = Item.find(:first)
30.times { i.clone.save }


Cody


On 12/8/05, Sean Schertell <sean@datafly.net> wrote:
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
http://www.codyfauser.com
55742d912a9003080d202c5522d4de00?d=identicon&s=25 rails (Guest)
on 2005-12-08 15:56
(Received via mailing list)
If it's in a test framework, you can do something like this:

200.times do
   MyModel.new({...}).save
end
450046d5f684ae5001c0b1a079d447d4?d=identicon&s=25 Sean Schertell (df-sean)
on 2005-12-08 16:16
Thanks so much guys.  Cody's tip was exactly what I was looking for.
Three helpful responses within 20 minutes of my post!  Oh I do love the
Rails community.  Cheers :-)
This topic is locked and can not be replied to.