0
  # Get only non-empty reviews
  query = Review.where("content <> ''")

  # filter on status (unreviewed, reviewed, flagged, etc), if provided
  if (status)
    query.where("status = ?", status)
  end

  # Order rows
  query.order("created_on ASC")

  # iterate, this should fire the query
  reviews = query.each_with_object([]) do |review, a|

我的问题是我的查询没有过滤“状态”。我已经检查了我的代码是否进入了 if 语句。我什至做到了:

  # Get only non-empty reviews
  query = Review.where("content <> ''")

  # filter on status (unreviewed, reviewed, flagged, etc), if provided
  query.where("status = ?", status)

我确定我做错了什么,但我不知道

4

1 回答 1

1

刚找到。每次都需要分配查询

  # Get only non-empty reviews
  query = Review.where("content <> ''")

  # filter on status (unreviewed, reviewed, flagged, etc), if provided
  query.where("status = ?", status)
于 2013-03-24T19:39:41.670 回答