我有一个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的表单。
我需要做些什么来完成这项工作?除了每次重新创建数据库时手动添加图标
答案 0 :(得分:1)
只需修改我的种子文件中的代码。以下作品:
activity = Activity.create! :name => 'Football', :icon => File.open(File.join(Rails.root, '/public/images/activity_icons/soccer.png'))