问题描述
我正在尝试在我的数据库中添加会员资料以及使用 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.
我可以在应用程序中创建/编辑现有成员以使用回形针 + S3 添加图片,它工作得很好,但播种它不起作用.我已经搜索过,但找不到答案.
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.
推荐答案
我不知道你的确切问题是什么,但你可以在你的种子.rb 文件中尝试这样的事情:
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 => 'user@name.fr'...})
u.avartar = File.open('/Users/myAccount/avatars/user.png')
u.save!
在您的 User.rb 文件中,您必须将 parperclip 配置为使用 amazon s3
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"
您可以在 dogan kaya berktas 博文上找到详细信息关于 s3.yml
You could find on dogan kaya berktas blog post detail about s3.yml
这篇关于如何通过 Paperclip + S3 使用种子数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!