开发者

Rake db:seed complaining about form not being multipart encoded

开发者 https://www.devze.com 2023-01-25 21:02 出处:网络
I have a seeds.rb file: activity1 = Activity.create! :name => \'Football\', :icon => File.read(\"#{Rails.root}/public/images/activity_icons/football.png\")

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


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'))
0

精彩评论

暂无评论...
验证码 换一张
取 消