除了轨道不工作

时间:2014-03-22 08:09:58

标签: ruby-on-rails ruby ruby-on-rails-3

我有这段代码:

  @note = @patient.notes.find(params[:id])
  @notes = @patient.notes.where(jahr: @note.jahr, quartal: @note.quartal).except(@note)

.except(@note)不起作用,我没有收到任何错误,@note仍然包含在@notes我错了什么?谢谢!

1 个答案:

答案 0 :(得分:2)

except用于跳过部分查询,如.except(:where)中跳过where子句。您可能希望使用类似.where('notes.id != ?', @note.id)的内容。或者在Rails 4中,where.not