[英]Indexing not working as expected in rails
在我的項目中,我想索引數據。
視圖代碼:
- @phones.each.with_index(1) do |(phone,no_of_duplicate),index|
.row.py-2
.col-2 = index
- if no_of_duplicate.count > 1
.col-3 = phone
.col-3 = no_of_duplicate.count
.col-4 .......................................
- @phones.each.with_index(1) do |(phone,no_of_duplicate),index|
- if no_of_duplicate.count > 1
.row.py-2
.col-2 = index
.col-3 = phone
.col-3 = no_of_duplicate.count
我該如何解決這個問題?
您可以在分配索引和渲染之前進行filter
:
@phones.filter { |(_,no_of_duplicate)| no_of_duplicate.count > 1 }.each <...>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.