Best Way to Include JavaScript from partials

This is just an idea off the top of my head, i.e. i haven't tried it.
Could you override the content_for method, (alias old_content_for ...
yada yada). Your new content_for will keep an array just like you
suggested and check if it's been loaded already. If you do it like this
you don't have to worry about the scoping of your array which seems to
be the issue you were having.