Rake db:种子抱怨表单不是多部分编码的

时间:2010-11-18 00:53:13

标签: ruby-on-rails ruby-on-rails-3 rake

我有一个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的表单。

我需要做些什么来完成这项工作?除了每次重新创建数据库时手动添加图标

1 个答案:

答案 0 :(得分:1)

通过following question

管理以解决此问题

只需修改我的种子文件中的代码。以下作品:

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