我正在将 Mongodb 与 ROR 一起使用。这是命令:
<%= render partial: "show", collection: @h %>
@h
在哪里
@h=[
{"folder"=>"Default", "weight"=>"100.0", "stocks"=>[
{"id"=>"id1", "name"=>"Ajanta Pharma Ltd.", "weight"=>"57.0"},
{"id"=>"id11", "name"=>"Avanti Feeds Ltd.", "weight"=>"5.1"},
{"id"=>"id34", "name"=>"MPS Ltd.", "weight"=>"2.5"},
{"id"=>"id89", "name"=>"Poly Medicure Ltd.", "weight"=>"3.7"}]},
{"folder"=>"low margin", "weight"=>"0.0", "stocks"=>[
]},
{"folder"=>"fjf", "weight"=>"0.0", "stocks"=>[
]}
]
假设我_show.erb
是这个
i am line
我得到的输出i am linei am linei am line
实际上是没有。如果我改成这个, @h
*内容中的文件夹的次数_show.erb
@h
@h=[
{"folder"=>"Default", "weight"=>"100.0", "stocks"=>[
{"id"=>"id1", "name"=>"Ajanta Pharma Ltd.", "weight"=>"57.0"},
{"id"=>"id11", "name"=>"Avanti Feeds Ltd.", "weight"=>"5.1"},
{"id"=>"id34", "name"=>"MPS Ltd.", "weight"=>"2.5"},
{"id"=>"id89", "name"=>"Poly Medicure Ltd.", "weight"=>"3.7"}]},
{"folder"=>"low margin", "weight"=>"0.0", "stocks"=>[
]}`
]
然后它给出i am linei am line
了文件夹是 2 的原因,因为它只需要一次输出,而不管是否。的文件夹。我怎样才能做到这一点?