Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Seed data with Paperclip + S3

I'm trying to seed my database with member profiles and also member profile pictures with S3 and paperclip but it doesn't seem to be working.

I can create/edit existing members within the application to add pictures with paperclip + S3 and it works just fine but seeding it doesn't work. I have searched but can't find an answer.

like image 404
Msencenb Avatar asked Jun 23 '11 06:06

Msencenb


1 Answers

I don't know what is your exact problem but you can try something like this in your seeds.rb file :

u = User.new({:name => 'username', :email => '[email protected]'...})
u.avartar = File.open('/Users/myAccount/avatars/user.png')
u.save!

In your User.rb file, you must have parperclip configured to work with amazon s3

has_attached_file :avatar,
    :styles => { :large => "177x177>", :thumb => "60x60>" },
    :storage => :s3,
    :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
    :path => "/avatars/:style/:id/:filename"

You could find on dogan kaya berktas blog post detail about s3.yml

like image 80
Guillaume Besse Avatar answered Sep 27 '22 18:09

Guillaume Besse