I have problem with my app in Rails 5. I create class scrape.rb
which
scraping HTML via Nokogiri gem and can save this data in another model, but when I create new object in rails console this return nil and don't scrap any value:
2.3.0 :018 > s = Scrape.new
=> #<Scrape:0x007fba68b79e98>
2.3.0 :019 > s.scrape_new_movie
=> nil
2.3.0 :020 >
Here is scrape.rb
model
class Scrape
attr_accessor :title, :vote, :image_url, :description,
def scrape_new_movie
begin
doc = Nokogiri::HTML(open("https://zalukaj.com/zalukaj-film/26280/barbie_w_wiecie_gier_barbie_video_game_hero_2017_.html").read, nil, 'utf-8')
doc.css('script').remove
self.title = doc.css('#pw_title.about_movie_title').text
v = doc.css('#success_vote').text
self.vote = v.slice(2...5)
self.image_url = doc.css('.about_movie img').attr('src').text
self.description = doc.css('#pw_description.e_s3k').text
return true
rescue Exception => e
self.failure = "Something went wrong with the scrape"
end
end
def save_movie
movie = Movie.new(
title: self.title,
vote: self.vote,
image_url: self.image_url,
description: self.description
)
movie.save
end
end