Managed to fix this thanks to the following question on stack
overflow
http://stackoverflow.com/questions/3910162/seeding-file-uploads-with-...

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

On Nov 18, 1:57 am, stephenjamesmurdoch
<stephenjamesmurd...@gmail.com> wrote:
> I'm using CarrierWave to attach icons to my activities model. I have a
> bunch of seed data that I want to create every time I recreate my
> database.
>
> The following line from my seeds.rb file causes rake to throw and
> error:
>
> activity = Activity.create! :name => 'Football', :icon =>
> File.read("#{Rails.root}/public/images/activity_icons/football.png")
>
> As you can see, I'm trying to upload a file from my public directory
> when I run rake db:seed.
>
> But when I do this, I get a complaint about my form not being
> multipart encoded.  I know that my form IS multipart encoded because
> manual uploads work fine and I've added the necessary code i.e. (:html
> => {:multipart => true}) to my form
>
> I'm guessing that this is not a CarrierWave issue since it would
> almost certainly happen if I was using paperclip or attachment_fu but
> perhaps some of you have dealt with this issue before?
>
> It seems to me that rake is not using the same form that is used for
> manual uploads (makes sense really) so is there a way to tell rake
> that this seed data should be considered multipart encoded?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to