在我的 Rails 应用程序中,现在我有这样的数据:
[[{:car=>"", :article=>"", :group=>"", :price=>""},
{:car=>"Volkswagen", :article=>"7H0127401A", :group=>"FILTER", :price=>"0,564"},
{:car=>"Volkswagen", :article=>"7H0127401B", :group=>"FILTER", :price=>"0,546"},
{:car=>"Volkswagen", :article=>"7H0127401D", :group=>"FILTER", :price=>"0,42"}],
[{:car=>"", :article=>"", :group=>"", :price=>""},
{:car=>"Volkswagen", :article=>"7H0127401A", :group=>"FILTER", :price=>"0,564"}],
[{:car=>"", :article=>"", :group=>"", :price=>""},
{:car=>"Volkswagen", :article=>"7H0127401B", :group=>"FILTER", :price=>"0,546"}]]
并查看:
=@oem_art.each do |oem|
-oem.each do |oo|
%tr{:class => cycle("zebra-stripe zebra-grey zebra1", "zebra-stripe zebra-grey zebra2")}
%td
= oo[:car]
%td
%h4
= oo[:article]
%td
= oo[:group]
%td
= oo[:price]
但我怎样才能以更美丽的方式做到这一点?另外如何用空键跳过散列?我怎样才能通过标准的一个循环来做到这一点,例如:
=@oem_art.each do |oem|
= oem.car
%td
=oem.price
怎么弄平?但是这里没用...
UPD
def original_art
@article = Article.find_by_ART_ID(params[:id])
@constr_num = ArtLookup.get_construction_number(@article.ART_ID)
oem_art = []
@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
@article = Article.first
@oem_art
end