我在这个视图中放置了一些条件,但问题是empty_matches
部分未加载,但另一方面,条件已满足。
这是视图:
%tr.form-table__row{ class: ('form-table__row--disabled' if analysis.processing?) }
%td.form-table__data= check_box_tag "checkbox_object_ids[]", analysis.id
%td.form-table__data
- if analysis.results.last.total_matches != 0
= link_to analysis.title, analysis, class: 'js-toggle', data: { href: "loading-#{analysis.id}" }
- elsif analysis.results.last.total_matches == 0
= link_to analysis.title, "#", class: 'js-toggle'
.
.
.
= render partial: 'partials/modals/analyses/delete', locals: { analysis: analysis }
- if analysis.results.last.total_matches != 0
= render partial: 'partials/shared/loading', locals: { href: "loading-#{analysis.id}", title: 'Loading results for analysis', name: analysis.title }
- elsif analysis.results.last.total_matches == 0
= render partial: 'partials/shared/empty_matches', locals: { href: "loading-#{analysis.id}", title: 'No matching results for analysis', name: analysis.title }
谁能告诉我为什么empty_matches
不是部分加载?满足条件loading
时成功加载另一个部分analysis.results.last.total_matches != 0
,但满足条件时不成功加载empty_matches
部分。我在这里错了吗?
您能否向我们展示您的total_matches
方法?假设它总是返回一个整数,我将使用这样的东西-
- if analysis.results.last.total_matches.zero?
= render partial: 'partials/shared/loading', locals: { href: "loading-#{analysis.id}", title: 'Loading results for analysis', name: analysis.title }
- else
= render partial: 'partials/shared/empty_matches', locals: { href: "loading-#{analysis.id}", title: 'No matching results for analysis', name: analysis.title }
https://docs.ruby-lang.org/en/2.5.0/Numeric.html#method-i-zero-3F