使用 rake db:seed 进行文件上传
我有一个使用 Paperclip 的应用程序,并且还使用 rake db:seed
生成一些可用于帮助引入新用户的演示帐户。
这些演示账户应包含的部分信息是对个人资料照片和将托管在 Amazon S3 上的其他文件的访问权限。
seeds
文件中的一个条目示例:
userdemo = User.find_or_create_by_login(:login => "demo",
:email => user.email,
:user_type => "admin",
:password => "demo",
:password_confirmation => "demo")
如何创建上述用户以及个人资料照片?这包括将文件从我的硬盘上传到 S3 并将该文件与此记录相关联。谢谢!
I have an app that uses Paperclip, and I am also using rake db:seed
to generate some demo accounts that can be used to help bring in new users.
Part of the information these demo accounts should contain are access to profile photos and other files that would be hosted on Amazon S3.
A sample of one entry in the seeds
file:
userdemo = User.find_or_create_by_login(:login => "demo",
:email => user.email,
:user_type => "admin",
:password => "demo",
:password_confirmation => "demo")
How can I create the above user along with a profile photo? This would include uploading a file from my hard drive to S3 and associating that file with this record. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议使用上传固定图像,按照 另一个 SO 线程
I'd suggest using uploading a fixture image, as per this other SO thread