HOLA! I’ve got the following ruby:
arr = (“0”…“99999”).sort{ rand(3) -1 } # shuffle-hack
arr.each do | item |
while item.length < 5
item.insert(0, ‘0’)
puts item # Wanna see 100,000 numbers with leading zeros?
end
end
== EOF ==
I want to put all these numbers in a table, each one a new row. Is it
possible to do this in a migration? I’ve been trying but I get a…
rake db:migrate…
Uninitialized constant Fillkeys::Key
error. (I’m putting the code in a migration, and replacing the #puts
line with
Key.create ( :key => item )
Comments? Suggestions?
On Jan 8, 2008, at 6:05 PM, MESSYKILL5000 wrote:
HOLA! I’ve got the following ruby:
arr = (“0”…“99999”).sort{ rand(3) -1 } # shuffle-hack
class Fillkeys < ActiveRecord::Migration
class Key < ActiveRecord::Base; end
def self.up
arr = (‘00000’…‘99999’).sort_by { rand }
arr.each do |item|
Key.create!(:key => item)
end
end
end
possible to do this in a migration? I’ve been trying but I get a…
rake db:migrate…
Uninitialized constant Fillkeys::Key
You do have a Key model in app/models/key.rb, right?
Better is to have a minimal Key model defined right inside the
migration class itself.
error. (I’m putting the code in a migration, and replacing the #puts
line with
Key.create ( :key => item )
Comments? Suggestions?
I hope that helps.
-Rob
Rob B. http://agileconsultingllc.com
[email protected]