Rake db:seed 抱怨表单未进行多部分编码
我有一个 seeds.rb 文件:
activity1 = Activity.create! :name => 'Football', :icon => File.read("#{Rails.root}/public/images/activity_icons/football.png")
但是当我运行 rake db:seed 时,该过程失败并收到一条错误消息:
You tried to assign a String or a Pathname to an uploader, for security reasons, this is not allowed.
If this is a file upload, please check that your upload form is multipart encoded.
嗯,手动图标上传确实有效,因为我的表单是 多部分编码,所以我猜测 rake 正在使用它自己的形式运行 seeds.rb。
我需要做什么才能使这项工作成功?除了每次重新创建数据库时手动添加图标之外
I have a seeds.rb file:
activity1 = Activity.create! :name => 'Football', :icon => File.read("#{Rails.root}/public/images/activity_icons/football.png")
But when I run rake db:seed, the process fails and I get an error message:
You tried to assign a String or a Pathname to an uploader, for security reasons, this is not allowed.
If this is a file upload, please check that your upload form is multipart encoded.
Well, manual icon uploads do work because my form is multipart encoded so I'm guessing that rake is using it's own form running seeds.rb.
What do I have to do to make this work? Besides manually adding the icons each time I recreate my db
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于以下问题,成功解决了这个
问题在我的种子文件中编写一些代码。以下作品:
Managed to fix this thanks to the following question
Just had to fix the code in my seeds file a bit. The following works: