Creating dummy users with Faker

This is how you add dummy users and image uploads with Faker.  Install the gem by adding it to your gemfile:

gem ‘faker’, ‘1.1.2’

I made a folder called ‘sampleimages’ in my app and put a few different images in it.  Next, I create a new ‘task’ under lib => tasks and call it populate.rake.  I fill it with the following:

namespace :db do
  desc "Fill database with sample data"
  task populate: :environment do
    10.times do |n|
      puts "[DEBUG] creating user #{n+1} of 10"
      name =
      email = "user-#{n+1}"
      password = "password"
      User.create!( name: name,
                    email: email,
                    password: password,
                    password_confirmation: password)

    User.all.each do |user|
      puts "[DEBUG] uploading images for user #{} of #{}"
      10.times do |n|
        image =, 'sampleimages', '*')).sample)
        description = %w(cool awesome crazy wow adorbs incredible).sample
        user.pins.create!(image: image, description: description)

Lastly, I run $ rake db:populate and this makes my site look pretty awesome on development!

Screen Shot 2013-04-07 at 9.40.51 PM