初期データをseed_fuを利用して登録するにあたり画像の登録ができなくて困っています。
http://qiita.com/ko2ic/items/be96e450a33d631e0059を参考にしてファイルを作成したのですがうまくいきません。
コード
(1..4).each do |i|
DressupImage.seed do |s|
s.id = i
s.product_id = (i%4)+1
s.front = Rails.root.join("db/fixtures/development/images/1_1.png").open
s.right_front = Rails.root.join("db/fixtures/development/images/1_2.png").open
s.right = Rails.root.join("db/fixtures/development/images/1_3.png").open
s.rear = Rails.root.join("db/fixtures/development/images/1_4.png").open
s.left_rear = Rails.root.join("db/fixtures/development/images/1_5.png").open
s.left = Rails.root.join("db/fixtures/development/images/1_6.png").open
s.left_front = Rails.root.join("db/fixtures/development/images/1_7.png").open
s.thumbnail = Rails.root.join("db/fixtures/development/images/1_8.png").open
s.thumbnail = Rails.root.join("db/fixtures/development/images/1_9.png").open
s.image0 = Rails.root.join("db/fixtures/development/images/1_10.png").open
s.image30 = Rails.root.join("db/fixtures/development/images/1_11.png").open
s.image60 = Rails.root.join("db/fixtures/development/images/1_12.png").open
s.image90 = Rails.root.join("db/fixtures/development/images/1_13.png").open
s.image120 = Rails.root.join("db/fixtures/development/images/1_14.png").open
s.image150 = Rails.root.join("db/fixtures/development/images/1_15.png").open
s.image180 = Rails.root.join("db/fixtures/development/images/1_16.png").open
s.image210 = Rails.root.join("db/fixtures/development/images/1_17.png").open
s.image240 = Rails.root.join("db/fixtures/development/images/1_18.png").open
s.image270 = Rails.root.join("db/fixtures/development/images/1_19.png").open
s.image300 = Rails.root.join("db/fixtures/development/images/1_20.png").open
s.image330 = Rails.root.join("db/fixtures/development/images/1_21.png").open
end
end
エラーメッセージ
== Seed from /Users/prin/ruby_app/ruby_app/db/fixtures/development/dressup_image.rb
- DressupImage {:id=>1, :product_id=>2, :front=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_1.png, :right_front=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_2.png, :right=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_3.png, :rear=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_4.png, :left_rear=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_5.png, :left=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_6.png, :left_front=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_7.png, :thumbnail=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_9.png, :image0=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_10.png, :image30=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_11.png, :image60=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_12.png, :image90=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_13.png, :image120=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_14.png, :image150=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_15.png, :image180=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_16.png, :image210=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_17.png, :image240=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_18.png, :image270=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_19.png, :image300=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_20.png, :image330=>#File:/Users/prin/ruby_app/ruby_app/db/fixtures/development/images/1_21.png}
rake aborted!
NoMethodError: undefined method id' for nil:NilClass (eval):2:in
block (3 levels) in run_file'
(eval):1:in `block (2 levels) in run_file'
Tasks: TOP => db:seed_fu
(See full trace by running task with --trace)
MacBook-Pro-2:ruby_app prin$
書き方が悪いのでしょうか?エラーになる原因の検討もつかない状態です。
どうかお知恵をお貸しください
あなたの回答
tips
プレビュー