如何从rails中的活动记录数组中删除记录?

时间:2015-07-03 07:16:46

标签: mysql ruby-on-rails-4

我想从活动记录查询结果数组中删除一个条目 所以我使用了以下代码:

<%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%>

这是一个错误:
未定义的方法`delete_at&#39;对于#&lt; MatchResult的:0x00000003a73a48&GT;

然后我用了:

<%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)

1 个答案:

答案 0 :(得分:1)

而不是删除使用drop:

<%match_results_comfirmation=match_results_comfirmation.drop(1)%>

这里1表示第1条记录。