这是一个index.html.erb。如何在备注属性列中不存在记录的情况下使用方法隐藏表头,如备注?最好不使用JavaScript。如果没有列属性,就隐藏表头 - Ruby on rails
index.html.erb
<table id = "kola" class="table listing text-center">
<% has_remark = collection_has_remark?(@aslani361s) %>
<thead>
<tr class="tr-head">
<td>Date</td>
<td>Description</td>
<td>Amount</td>
<td>Discount</td>
<td>Paid</td>
<td>Balance</td>
<td>DelnDel</td>
<% if has_remark %>
<td>Remark</td>
<% end %>
<td>Hide</td>
</tr>
</thead>
</table>
但是我能够隐藏备注属性值类似如下;
_aslani361.html.erb
<% if aslani361.remark.present? -%>
<td class="col-1"><%= aslani361.remark %></td>
<% end %>
aslani361s_helper.rb
module Aslani361sHelper
def collection_has_remark?(collection)
collection.each do |aslani361|
if aslani361.remark.present?
return true
end
end
end
end
aslani361.rb
class Aslani361 < ActiveRecord::Base
end
任何建议者居多。
预先感谢您。
难道你不能做同样的事情,你做隐藏的属性值?只需在if语句中包装Remark标题 – davidhu2000
你可以发布你的模型吗?如果不知道备注的存储位置,它们与其他模型的关系如何,几乎不可能拿出用来检查整列的代码。 – jaydel
感谢您的回复。如何使用if语句来包装Remark标题? –