当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby on rails 3 - 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.

网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: