Having trouble setting up a Rake Task. Here is the code:
task :fetch_games => :environment do
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::XML(open(url))
games = doc.xpath('//game')
games.each do |game|
@data = Game.new(
:name => game.at('name').text,
:publisher => game.at('publisher').text,)
@data.save
if @data.save
puts "Success"
else
puts "Didn't work"
end
end
end
It runs without error but in the database the entries show: “— !ruby/object:Nokogiri::XML::Element {}
“
Any help would be awesome. Thanks!
Figured it out myself the xpath syntax was incorrect. I need to use:
instead of