Upload test images using rake with populator

I am wondering if it is possible to upload test images to the database
along with the other fake user data. I am using populator along with
faker for fake test data and it is working very well. I am able to do
things like:

User.populate 100 do |user|
  user.username = Faker::Name.first_name
  user.email    = Faker::Internet.email

end

but I am wondering if theres a way to do something like:

User.populate 100 do |user|
  user.username = Faker::Name.first_name
  user.email    = Faker::Internet.email
 Photo.populate 1 do |photo|
   photo.user_id = user.id ....

end

I know this is not possible with populator, but maybe someone can
enlighten me with the direction towards a function I can write on my
own? I am using attachment_fu now, but I am looking to switch to
paperclip in the near future. Also if anyone has other methods
excluding rake tasks for doing this please let me know. thanks.

Just found this relevant code online. Gonna play around with this and
see where I get:

namespace :avatars do
  desc "Create initial avatar database."
  task :init => :environment do
    Dir.chdir("#{RAILS_ROOT}/public/avatars/")
    @image_paths = Dir["*.jpg"]
    for avatar in @image_paths
      path = "#{RAILS_ROOT}/public/avatars/#{avatar}"
      fsize = File.size(path)
      avatar = Avatar.create(:avatar_file_name =>

avatar, :avatar_content_type => ‘image/jpeg’, :avatar_file_size =>
fsize)
avatar.save
end
end
end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs