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
On Dec 4, 3:33 am, David <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---