Some example code that shows how to do that:
SKIP_COLUMNS = %w(id created_at updated_at)
RECORDS_COUNT = 10
# random data to fill
int = rand(1..100)
varchar = 'lorem'
text = 'big lorem'
# get models
@models = ActiveRecord::Base.connection.tables.collect {|t| t.underscore.singularize.camelize }
@models.select {|m| m.constantize rescue @models.delete(m) }
# fill in data
@models.map(&:constantize).each do |model|
model.columns_hash.each do |column|
next if SKIP_COLUMNS.include?(column.first)
# column_name = column.first
# column_type = column.last.type
RECORDS_COUNT.times do
record = model.new
case column.last.type
when :integer
record.send("#{column.first}=", int)
when :string
record.send("#{column.first}=", varchar)
when :text
record.send("#{column.first}=", text)
end
record.save!
end
end
end
You can put that to rake task.