设置 Rake 任务时遇到问题。这是代码:
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
它运行没有错误,但在数据库中的条目显示:“--- !ruby/object:Nokogiri::XML::Element {}”
任何帮助都是极好的。谢谢!