I use the same idea for enabling users to add infinite number of
attachments and other things. However, I don't use a variable and
increment, instead I use the time as follows:
<% index = Time.now.tv_sec %>
<input id="attachment_data" name="attachment[<%=index%>][data]"
size="30" type="file" />