[英]How to delete an record from array of active record result in rails?
我想从活动记录查询结果数组中删除一个条目。
所以我用下面的代码:
<%match_results_comfirmation=MatchResult.where("challenge_id IN (?)",chllenges_ids)%>
<%match_results_comfirmation_loop.each do|j|%>
<%match_results_comfirmation=match_results_comfirmation.delete_at(0)%>
<%end%>
这给出了一个错误:
#<MatchResult:0x00000003a73a48>的未定义方法`delete_at'
然后我用了:
<%match_results_comfirmation=MatchResult.where("challenge_id IN (?)",chllenges_ids)%>
<%match_results_comfirmation_loop.each do|j|%>
<%match_results_comfirmation=match_results_comfirmation.delete(j)%>
<%end%>
但是然后它给出了一个错误:参数数量错误(1代表0)
代替删除,使用drop:
<%match_results_comfirmation=match_results_comfirmation.drop(1)%>
这里1表示第1条记录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.