【问题标题】:undefined method 'x' for #<#< 的未定义方法“x”
【发布时间】:2020-03-26 03:18:32
【问题描述】:

我已经在analysis_result.rb 中定义了这个:

 def total_matches
 ...
 end

我正在尝试在 _rable_row.haml 这样的视图中使用它:

- if analysis.results.total_matches != 0
  = link_to analysis.title, analysis, class: 'js-toggle', data: { href: "loading-#{analysis.id}" }
- elsif analysis.results.total_matches == 0
  = render partial: 'partials/shared/empty'

但我收到了undefined method 'total_matches' for #&lt;Mongoid::Criteria:

谁能告诉我为什么会这样?

【问题讨论】:

  • @analysis 为零。这就是问题
  • @Pavan 好的,我明白了。我更改为 analysis.results。你现在可以检查我的问题吗?

标签: ruby-on-rails ruby haml


【解决方案1】:

出现错误undefined method 'total_matches'是因为total_matches不能直接在results数组上调用,它是结果数组中存在的对象的属性。 IE。您试图在对象数组上调用对象的属性,而不是在对象本身上。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多