title: Rails communicating with jquery through erb
body: <p>I'm querying Rails for whether a record exists through a has many through relationship in erb:</p>
  
  <pre><code>&lt;% if @hack.serials %&gt;
  </code></pre>
  
  <p>Ultimately if a 'serial' does not exist within the '@hack' I want to add 'display: none' to a div's class through jquery.</p>
  
  <p>Is there a pattern for communicating between rails and jquery through erb in this way?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>The idea here is that if there's no data, than the I don't want the tabs and its content to show up.  And until the 'hack' is edited and the page is reloaded the div "chart-table" will not have data, so will not need to become visible.</p>
  
  <pre><code>&lt;div class = "chart-table" 
    &lt;% if @hack.serials %&gt;
      &lt;%= raw 'style="display:block"' %&gt;
    &lt;% end %&gt;&gt;
  &lt;!-- TABS --&gt;
  &lt;div id="tabs"&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href="#tabs-1"&gt;Chart&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="#tabs-2"&gt;Last 5 Table&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;!-- CHART --&gt;
  &lt;div id="tabs-1"&gt;
    &lt;div id="container" style="height: 500px; min-width: 500px"&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- TABLE --&gt;
  &lt;div id="tabs-2"&gt;
    &lt;table class = "table-condensed"&gt;
      &lt;%= @hack.id %&gt;
      &lt;% @hack.serials.each do |s| %&gt;  
      &lt;tr&gt;
         &lt;th&gt;Series Title&lt;/th&gt;
          &lt;th&gt;Series Name&lt;/th&gt;
          &lt;th&gt;Series Id&lt;/th&gt;
        &lt;% s.observations.sort{|a,b| a.id &lt;=&gt; b.id}.last(5).each do |o| %&gt;
          &lt;th&gt;&lt;%= o.date %&gt;&lt;/th&gt;
        &lt;% end %&gt;
      &lt;/tr&gt;    
      &lt;tr&gt;
        &lt;td&gt;&lt;%= link_to s.title, [@hack, s] %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= s.series_name %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= s.id %&gt;&lt;/td&gt;
      &lt;% s.observations.sort{|a,b| a.id &lt;=&gt; b.id}.last(5).each do |o| %&gt;
        &lt;% if s.units_short == 'Mil. of $' %&gt;
          &lt;td&gt;&lt;%= number_to_currency(convertMtoBHack(o.value), :precision =&gt; 0) %&gt;&lt;/td&gt;
          &lt;% else %&gt;
            &lt;td&gt;&lt;%= number_to_currency(o.value, :precision =&gt; 0) %&gt;&lt;/td&gt;
          &lt;% end %&gt;
        &lt;% end %&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;%= s.frequency_short %&gt;&lt;/td&gt;
        &lt;td&gt;&lt;%= s.units_short %&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;% end %&gt;
    &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>
  </p>