Skip to content

Instantly share code, notes, and snippets.

@rubytastic
Created February 11, 2012 11:24
Show Gist options
  • Save rubytastic/1798870 to your computer and use it in GitHub Desktop.
Save rubytastic/1798870 to your computer and use it in GitHub Desktop.
namespace :db do
desc "Populate Users Table with images from /public/feedimg"
task :populate => :environment do
require "populator"
require "faker"
User.populate 1 do |user|
user.username = Faker::Name.first_name.downcase
user.email = Faker::Internet.user_name + "@myhost.com".downcase
user.encrypted_password = "27e50904b7a1c29a43e347eef5f6144303b516b7364a4a093e022435e0b3479024d57cbfds32499c30154a1a3e0d903c12b320c4f44844aa4d52c49b31f58f"
user.password_salt = "ZqZjUzrphRQo7nd4y346"
user.confirmed_at = DateTime.now
user.created_at = DateTime.now
end
Asset.all.each {
|asset| asset.file = File.open(Dir.glob(File.join(Rails.root, '/public/feedimg', '*')).sample);
asset.attachable_id = user.id;
asset.save! }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment