私はそのようなコントローラーアクションを持っています:
@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.車など...