1
無法設置Rake任務。下面是代碼:Rails:使用Nokogiri插入Rake任務解析:---!ruby/object:Nokogiri :: XML :: Element {}進入DB
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
運行沒有錯誤,但在數據庫中的條目顯示: 「---紅寶石/對象:引入nokogiri :: XML ::元素{} 」
任何幫助會很棒。謝謝!