Я пытаюсь разобрать открытый XML-файл данных из Интернета в мою базу данных rails. Ниже приведен код, который должен разобрать его:TypeError: неявное преобразование String в Integer
require 'rake'
require 'open-uri'
namespace :db do
task :xml_parser => :environment do
doc = Nokogiri::XML(open("https://dl.dropboxusercontent.com/u/21695507/openplaques/gb_20151004.xml"))
doc.css('plaque').each do |node|
children = node.children
Plaque.create(
:title => children.css('title').inner_text,
:subject => children.css('subjects').inner_text,
:colour => children.css('colour').inner_text,
:inscription => children.css('inscription raw').inner_text,
:latitude => children.css('geo')["latitude"].text,
:longitude => children.css('geo')["longitude"].text,
:address => children.css('address').inner_text,
:organisation => children.css('organisation').inner_text,
:date_erected => children.css('date_erected').inner_text
)
end
end
end
А вот схема:
create_table "plaques", force: :cascade do |t|
t.string "title"
t.string "subject"
t.string "colour"
t.text "inscription"
t.string "latitude"
t.string "longitude"
t.text "address"
t.text "organisation"
t.string "date_erected"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
бегаю грабли БД: XML_Parser и я получаю следующее сообщение об ошибке:
TypeError: no implicit conversion of String into Integer
Ниже это образец из файла XML, который я пытаюсь проанализировать.
<plaque uri="http://openplaques.org/plaques/4856" machine_tag="openplaques:id=4856" created_at="2010-11-26T13:58:23+00:00" updated_at="2011-06-28T17:00:01+01:00">
<title>Arthur Linton blue plaque</title>
<subjects>Arthur Linton</subjects>
<colour>blue</colour>
<inscription>
<raw>
World Champion Cyclist 1895 lived here Arthur Linton 1872-1896
</raw>
<linked>
World Champion Cyclist 1895 lived here <a href="/people/2934">Arthur Linton</a> 1872-1896
</linked>
</inscription>
<geo reference_system="WGS84" latitude="51.7005" longitude="-3.4251" is_accurate="true" />
<location>
<address>Sheppard's Pharmacy, 218 Cardiff Road</address>
<locality uri="http://0.0.0.0:3000/places/gb/areas/aberaman/plaques">Aberaman</locality>
<country uri="http://0.0.0.0:3000/places/gb">United Kingdom</country>
</location>
<organisation uri="http://0.0.0.0:3000/organisations/rhondda_cynon_taf_council">Rhondda Cynon Taf Council</organisation>
<date_erected>2009-10-26</date_erected>
<person uri="http://0.0.0.0:3000/people/2934">Arthur Linton</person>
</plaque>
'children.css ('geo') [" latitude "]. Text' - это не так, как вы, по-видимому, получаете значения атрибутов. Однако я не знаю, что такое правильный апи. Это зависит от вас, чтобы узнать :) –