這是一個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標題? –