0

我正在使用rets gem 下载房地产数据。

我正在尝试传递:no_records_not_an_errorfind命令,但我无法正确使用语法:

:no_records_not_an_error => true

我已经尝试了许多不同的迭代,使用括号、嵌套括号、带和不带逗号,但我一直无法找到正确的语法:

properties = client.find (:all, :no_records_not_an_error => true), {
  search_type: 'Property',
  class: klass,
  query: status_query,
  limit: 2000,
  offset: offset,
  select: columns_system.join(',')
}

此代码可以在没有 的情况下工作no_records..,但是当没有搜索结果时,它会在最后出现错误。当没有搜索结果时,我希望此代码返回 0 或 nil。

4

1 回答 1

1

你这样写怎么样

properties = client.find (:all), {
  no_records_not_an_error: true,
  search_type: 'Property',
  class: klass,
  query: status_query,
  limit: 2000,
  offset: offset,
  select: columns_system.join(',')
}

或者你可以简单地删除 no_records_not_an_error 选项,然后写

properties.compact

这将删除属性中的所有 nil 值

于 2015-11-06T18:01:33.697 回答