2013-01-21 56 views
1

我正在使用回形針,但不知道如何播種。如何在導軌中播種照片

我有一個佔位符,在我的本地路徑(OSX)爲/Users/me/dev/APP/doc/seeding/300x220.jpg

我的種子文件是:

p = Photo.new({:description => 'one', :created_at => "Sun, 1 Jan 2012 01:01:01 -0500".to_datetime, :updated_at => "Sun, 1 Jan 2012 01:01:01 -0500".to_datetime }) 
p.image_file_name = File.open(Rails.root.join('doc', 'seeding', '300x220.jpg')) 
p.save! 

我的錯誤返回:

No such file or directory - /Users/me/dev/APP/doc/seeding/300x220.jpg 
/Users/me/dev/APP/db/seeds.rb:20:in `initialize' 
/Users/me/dev/APP/db/seeds.rb:20:in `open' 
/Users/me/dev/APP/db/seeds.rb:20:in `<top (required)>' 
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load' 
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `block in load' 
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency' 
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load' 
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/railties-3.2.11/lib/rails/engine.rb:520:in `load_seed' 
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/activerecord-3.2.11/lib/active_record/railties/databases.rake:333:in `block (2 levels) in <top (required)>' 
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `eval' 
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `<main>' 
Tasks: TOP => db:setup => db:seed => db:seed:common => db:seed:original 

Searching the rdoc for paperclip,沒有返回。

其他文件,可能會有所幫助:

架構的照片:

create_table "photos", :force => true do |t| 
t.string "description" 
t.datetime "created_at",   :null => false 
t.datetime "updated_at",   :null => false 
t.string "image_file_name" 
t.string "image_content_type" 
t.integer "image_file_size" 
t.datetime "image_updated_at" 
end 

回答

1
photo.image = File.open(file_path) 
photo.save! 
+0

翻出來,你讓我查的權限。他們很好,但OSX不知何故有雙文件擴展名,造成這個問題。 ('-rw-r - r - @ 1 me staff 3605 Jan 20 18:58 300x220.jpg.jpg'),即使Finder將它作爲.jpg感謝您幫助我驗證語法.. –

相關問題