【问题标题】:Rets Gem Syntax ruby/rails no_records_no_errorRets Gem 语法 ruby​​/rails no_records_no_error
【发布时间】:2015-11-06 17:44:57
【问题描述】:

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

我正在尝试将:no_records_not_an_error 传递给find 命令,但我无法正确获取语法:

: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。

【问题讨论】:

  • “它因错误而中断”?什么错误?我们需要知道这类信息。请提供一小段代码,我们可以运行它来生成您看到的错误。

标签: ruby ruby-on-rails-3.2 rets


【解决方案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-02-04
    • 2017-06-15
    • 2013-07-27
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多