title: How do you write a conditional ternary operator inline in Ruby on Rails?
body: <p>I am trying to compare 2 values and change the color of one when the condition holds true.
  But I also have a search-bar and I could not access the tag values when it is wrapped in an &lt;% if %> statement in my javascript function using Rails. </p>
  
  <p>I originally had the code as so</p>
  
  <pre><code> &lt;% if track.user.username == current_user.username%&gt;
     &lt;td class="track_table_current_user"&gt;
       &lt;span&gt;&lt;%= track.user.username %&gt;&lt;/span&gt;
     &lt;/td&gt;
   &lt;% else %&gt;
     &lt;td class="td-userName"&gt; 
       &lt;span class="track_table_user_name"&gt;&lt;%= track.user.username %&gt; &lt;/span&gt;
     &lt;/td&gt;
   &lt;% end %&gt; 
  </code></pre>
  
  <p>My Ternary as of now: </p>
  
  <pre><code>&lt;td class="track_table_user_name &lt;% track.user.username == current_user.username ? "this_current_user" : "other_user" %&gt;"&gt;
      &lt;%= track.user.username %&gt;
  &lt;/td&gt;
  </code></pre>
  
  <p>The Search Function that I cannot access the values if I use an &lt;% if %> &lt;% else%>:</p>
  
  <pre><code>function trackTableSearch() {
    var input, filter, table, tr, td, i, txtValue;
    input = document.getElementById("trackTableInput");
    filter = input.value.toUpperCase();
    table = document.getElementById("tracksTable");
    tr = table.getElementsByTagName("tr");
    for (i = 0; i &lt; tr.length; i++) {
      tdN  = tr[i].getElementsByClassName("td-trackName")[0];
      tdU = tr[i].getElementsByClassName("track_table_user_name")[0];
      tdR = tr[i].getElementsByClassName("td-trackApproved")[0];
      tdP = tr[i].getElementsByClassName("td-public")[0];
      if ((tdN) || (tdU) || (tdR) || (tdP)) {
        txtValueN  = tdN.textContent  || tdN.innerText;
        txtValueU  = tdU.textContent  || tdU.innerText;
        txtValueA  = tdR.textContent  || tdR.innerText;
        txtValueP  = tdP.textContent  || tdP.innerText;
  
        if (txtValueN.toUpperCase().indexOf(filter) &gt; -1) {
          tr[i].style.display = "";
        }else if (txtValueU.toUpperCase().indexOf(filter) &gt; -1) {
          tr[i].style.display = "";
        } else if (txtValueA.toUpperCase().indexOf(filter) &gt; -1) {
          tr[i].style.display = "";
        }else if (txtValueP.toUpperCase().indexOf(filter) &gt; -1) {
          tr[i].style.display = "";
        }else{
          tr[i].style.display = "none";
        }
      }
    }
  </code></pre>