我正在使用带有ROR的Mongodb。这是命令:
<%= 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
然后它给{{1}}作为文件夹是2为什么它发生,因为只想要一次输出而不管是否。的文件夹。我怎么能这样做?
答案 0 :(得分:0)
完成,实际当您通过:collection选项将集合传递给partial时,将为集合中的每个成员插入一次partial:
所以我使用了这个:&lt;%= render partial:“show”,object:@h%&gt;