News-api (https://newsapi.org/)を使ってニュースを取得して保存したいが保存するときに
NoMethodError: undefined method `each' for nil:NilClassが出てしまいます。なにかわかる方回答お願いします。参考
https://note.com/hikkymouse_pro/n/nfccc6cc6cf8d
rails db:seed rails aborted! NoMethodError: undefined method `each' for nil:NilClass C:/Users/user/Desktop/home/db/seeds.rb:13:in `<top (required)>' ...
seedrb
1uri1 = URI.parse("http://newsapi.org/v2/top-headlines?country=jp&apiKey=自分のAPI") 2json1= Net::HTTP.get(uri1) 3publishers_to_rb = JSON.parse(json1) 4publishers = publishers_to_rb["sources"] 5publishers.each do |data| 6 Publisher.create(author: data['author'], description: data['description'], title:data['title'], url:data['url'], urlToImage:data['urlToImage'], publishedAt:data['publishedAt'],content:data['content']) 7end 8
create_table :publishers do |t| t.string :author t.string :title t.text :description t.string :url t.string :urlToImage t.string :publishedAt t.text :content t.timestamps end
初めて使う技術なのでわからないことが多いです。他に記載しなければならないことがあればコメントお願いします。

回答1件
あなたの回答
tips
プレビュー