本文介绍了如何在 Rails 中播种照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用回形针,但不确定如何使用/不使用它进行播种.

I am using paperclip, but not sure how to seed with/without it.

我有一个占位符,在我的本地路径 (OSX) 中为 /Users/me/dev/APP/doc/seeding/300x220.jpg

I have a placeholder, in my local path (OSX) as /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 中搜索回形针,没有任何返回.

其他可能有帮助的文件:

Other documents that might be of help:

照片架构:

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!

这篇关于如何在 Rails 中播种照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 06:29