[英]Indexing not working as expected in rails
In my project I want to index the data.在我的项目中,我想索引数据。
The code of views:视图代码:
- @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 .......................................
I obtain the result as我得到的结果是
If I change the code on views as:
如果我将视图上的代码更改为:
- @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
How can I solve this?我该如何解决这个问题?
您可以在分配索引和渲染之前进行filter
:
@phones.filter { |(_,no_of_duplicate)| no_of_duplicate.count > 1 }.each <...>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.