I have the following code in my HTML where I am trying to pass a Ruby variable to the JavaScript function. Can someone please help me with the syntax?
<% @level2.each_with_index do |row2, index2| %>
................................................
................................................
<a href="javascript:validateUser_com("<%= #{index2} %>")" >Edit</a>
You’re using double quotes twice. For example, if
index2is1, you end up with the following JavaScript:Since you’re using double quotes for the HTML attribute, you should escape the inner quotes or use single quotes. Furthermore, the Ruby expression is not a string, so there’s no need for interpolation: