前提・実現したいこと
具体的に何が原因になっていて、どのような処理をすればいいのでしょうか?
発生している問題・エラーメッセージ
NameError: undefined local variable or method `director' for Scraping:Class from /projects/mooovi/app/models/scraping.rb:29:in `get_product'
該当のソースコード
class Scraping
def self.movie_urls
links = []
agent = Mechanize.new
next_url = ""
while true current_page = agent.get("http://review-movie.herokuapp.com/" + next_url) elements = current_page.search('.entry-title a') elements.each do |ele| links << ele.get_attribute('href') end next_link = current_page.at('.pagination .next a') break unless next_link next_url = next_link.get_attribute('href') end links.each do |link| get_product('http://review-movie.herokuapp.com' + link) end
end
def self.get_product(link)
agent = Mechanize.new
page = agent.get(link)
title = page.at('.entry-title').inner_text if page.at('.entry-title')
image_url = page.at('.entry-content img')[:src] if page.at('.entry-content img')
product = Product.where(director: director, detail: detail, open_date: open_date).first_or_initialize
product.director = director
product.detail = detail
product.open_date = open_date
product.save
end
end
Ruby
試したこと
全角のスペースを探した
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
あなたの回答
tips
プレビュー