我正在尝试更新数组的所有元素,但出现此错误
未定义的方法“update_all”用于...
@group.questions.where(user_id: current_user.id).last(@post.question_counter).update_all(post_id: @post.id)
当我尝试在没有条件的情况下更新_all时:
@group.questions.update_all(post_id: @post.id)
该方法正在起作用。您有运行此方法的解决方案吗?我可以做这样的事情来解决它,但我认为这不是很优雅和高性能
@questions = @group.questions.where(user_id: current_user.id).last(@post.question_counter)
@questions.each do |question|
question.update(post_id: @post.id)
end