make working in console but no in seeds.rb

63 views
Skip to first unread message

Florent2

unread,
May 31, 2010, 4:23:05 PM5/31/10
to Machinist Users
Hello,

I have a Photo model using Paperclip to store the photo:

class Photo < ActiveRecord::Base
has_attached_file :file
validates_attachment_presence :file
validates_attachment_content_type :file, :content_type => ['image/
jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif']
end

In my blueprints.rb file, I have:

Photo.blueprint do
file File.new(Rails.root.join('spec', 'fixtures', 'photos',
'example.jpg'))
end

From the console I can successfully create a new Photo instance with
"Photo.make".

But if I ran "rake db:seeds" with db/seeds.rb like:

require Rails.root.join('spec').join('blueprints')
Photo.delete_all
Photo.make

Photo.make does not work, I got an error "Validation failed: File file
name must be set., File content type".

I don't understand why Photo.make works from the console but not with
"rake db:seed". I am using Rails 3.0.0.beta3, Machinist 1.0.6 and the
Rails3 branch of Paperclip.

Any help would be appreciated :)

Regards,
Florent

Pete Yandell

unread,
Jun 14, 2010, 8:59:13 PM6/14/10
to Machinist Users
For starters, your blueprint needs to read:

Photo.blueprint do
file { File.new(Rails.root.join('spec', 'fixtures', 'photos',
'example.jpg')) }
end

Without the braces, you're creating the File at load time, so load
order might be biting you.

Not sure if that's the issue, but try it and see what happens.

- Pete

Florent Florent

unread,
Jun 15, 2010, 9:17:25 AM6/15/10
to machini...@googlegroups.com
Thanks

2010/6/14 Pete Yandell <pe...@notahat.com>
Thanks for your answer Pete. Unfortunately adding the braces does not solve the issue, I still face the same problem. Anyway meanwhile I change my seeds file to create Photo instances directly with create! instead of make.

Florent
Reply all
Reply to author
Forward
0 new messages