> I'm not sure if this is the correct, I think you will end up w. duplicate indices if a fieldset is removed.

If a fieldset is removed, the number will just keep counting up. So you might have some numbers not used at all, but at least they won't conflict.

> Also I don't quite understand what you mean about storing the index and how it helps with multiple has_many forms

If I had a global variable that stored the current index, that wouldn't act sanely if you have mutliple has_many forms. Whereas this solution binds the index onto the add button, so it's unique to every has_many form.