erb の has many の関係を介してレコードが存在するかどうかを Rails に問い合わせています。
<% if @hack.serials %>
最終的に、「シリアル」が「@hack」内に存在しない場合、jquery を使用して「display: none」を div のクラスに追加したいと考えています。
このようにerbを介してレールとjqueryの間で通信するためのパターンはありますか?
編集
ここでの考え方は、データがない場合、タブとそのコンテンツを表示したくないということです。また、「ハック」が編集されてページがリロードされるまで、div「チャートテーブル」にはデータがないため、表示する必要はありません。
<div class = "chart-table"
<% if @hack.serials %>
<%= raw 'style="display:block"' %>
<% end %>>
<!-- TABS -->
<div id="tabs">
<ul>
<li><a href="#tabs-1">Chart</a></li>
<li><a href="#tabs-2">Last 5 Table</a></li>
</ul>
<!-- CHART -->
<div id="tabs-1">
<div id="container" style="height: 500px; min-width: 500px"></div>
</div>
<!-- TABLE -->
<div id="tabs-2">
<table class = "table-condensed">
<%= @hack.id %>
<% @hack.serials.each do |s| %>
<tr>
<th>Series Title</th>
<th>Series Name</th>
<th>Series Id</th>
<% s.observations.sort{|a,b| a.id <=> b.id}.last(5).each do |o| %>
<th><%= o.date %></th>
<% end %>
</tr>
<tr>
<td><%= link_to s.title, [@hack, s] %></td>
<td><%= s.series_name %></td>
<td><%= s.id %></td>
<% s.observations.sort{|a,b| a.id <=> b.id}.last(5).each do |o| %>
<% if s.units_short == 'Mil. of $' %>
<td><%= number_to_currency(convertMtoBHack(o.value), :precision => 0) %></td>
<% else %>
<td><%= number_to_currency(o.value, :precision => 0) %></td>
<% end %>
<% end %>
</tr>
<tr>
<td><%= s.frequency_short %></td>
<td><%= s.units_short %></td>
</tr>
<% end %>
</table>
</div>