ここにindex.html.erbがあります。注釈属性列にレコードが存在しないときに、メソッドでRemarkなどのテーブルヘッダーを非表示にするにはどうすればよいですか? 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ヘッダをラップするのですか? –