I have a Ruby-on-Rails web application in which I need to pass a variable in to a javascript function. Easy enough if I just want to do something like this:
<a href="#" onclick="javascript:show_details('section_1')">Show Details</a>
However, what I need to do is something like this:
<% 4.times do |n| %>
<a href="#" onclick="javascript:show_details('section_" + n + "')">Show Details</a>
<% end %>
Where the parameter being passed to show_details would resolve to 'section_1' then 'section_2' then 'section_3' and finally 'section_4'
I assume this is probably pretty easy but so far I'm kind of stuck.
Any suggestions?
Thanks in advance!
<%= %>thing in rails. If yes, this will work:<a href="#" onclick="javascript:show_details('section_<%= n %>')">Show Details</a>