Q: Rails 4: Changing Table Values with JavaScript Buttons I want to use JavaScript in my rails 4 scaffold. In my table I want when I click a button (javascript button) it changes the values on that table column. My table has a loop:
<% @x.each do |y| %>
 <%= y.method %>
<% end %>

Out of that loop I will have:
<button type="button"
  onclick="document.getElementById('t1').innerHTML = <%= y.method1 %>">
  Type 1.
</button>

<button type="button"
  onclick="document.getElementById('t1').innerHTML = <%= y.method2 %>">
  Type 2.
</button>

<button type="button"
  onclick="document.getElementById('t1').innerHTML = <%= y.method3 %>">
  Type 3.
</button>

And in the loop as above table:
<% @x.each do |y| %>
 <td id="t1"></td>
<% end %>

Sure enough I get undeclared method "y". But If I put the loop around the javascript buttons it work BUT...in the table only one row's value changed. What's the correct way around it?

A: I guess you forgot to wrap value of innerHTML into "" :
onclick="document.getElementById('t1').innerHTML = \"<%= y.method3 %>\"">

Plus, it looks like you may have more than 1 td with id t1, which is wrong. So use classes instead(but in this case your code with assigning innerHTML to the all elements with class someClass will be much larger)
