如何在铁轨上播种照片



我正在使用回形针,但不确定如何使用/不使用它。

我有一个占位符,在我的本地路径(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

在rdoc中搜索回形针,没有返回任何结果。

其他可能有帮助的文档:

Schema for Photo:

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
photo.image = File.open(file_path)
photo.save!

相关内容

  • 没有找到相关文章

最新更新