开发者

Rake db:seed complaining about form not being multipart encoded

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜