Rake db:seed 抱怨表单未进行多部分编码

发布于 2024-10-03 09:45:23 字数 604 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铜锣湾横着走 2024-10-10 09:45:23

由于以下问题,成功解决了这个

问题在我的种子文件中编写一些代码。以下作品:

activity = Activity.create! :name => 'Football', :icon => File.open(File.join(Rails.root, '/public/images/activity_icons/soccer.png'))

Managed to fix this thanks to the following question

Just had to fix the code in my seeds file a bit. The following works:

activity = Activity.create! :name => 'Football', :icon => File.open(File.join(Rails.root, '/public/images/activity_icons/soccer.png'))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文