我有这样的控制器动作:
@constr_num.each do |o|
as_oem = get_from_as_oem(o.ARL_SEARCH_NUMBER)
if as_oem.present?
oem_art << as_oem
end
end
@oem_art = oem_art.to_a.uniq
get_from_as_oem 看起来像这样:
def get_from_as_oem(oem)
require 'mechanize'
*************************
html = page.body
doc = Nokogiri::HTML(html)
doc.encoding = 'utf-8'
rows = doc.search('//table[@id = "MainContent_GridView1"]//tr')
@details = rows.collect do |row|
detail = {}
[
[:car, 'td[1]/text()'],
[:article, 'td[2]/text()'],
[:group, 'td[3]/text()'],
[:price, 'td[4]/text()'],
].each do |name, xpath|
detail[name] = row.at_xpath(xpath).to_s.strip
end
detail
end
@details
end
如果在视图中我写:=@oem_art 我得到
[[{:car=>"", :article=>"", :group=>"", :price=>""}, {:car=>"Volkswagen", :article=>"1C0959799B 001", :group=>"STEUERG.", :price=>"274,22"}, {:car=>"Volkswagen", :article=>"1C0959799B 003", :group=>"STEUERG.", :price=>"274,22"}, {:car=>"Volkswagen", :article=>"1C0959799B 00E", :group=>"STEUERG.", :price=>"274,22"}, {:car=>"Volkswagen", :article=>"1C0959799B 00F", :group=>"STEUERG.", :price=>"274,22"}, {:car=>"Volkswagen",
etc...
那我怎么能正常查看它,例如 .each |c| c.汽车等...