# Best Way to Include JavaScript from partials

**URL:** <https://discuss.rubyonrails.org/t/best-way-to-include-javascript-from-partials/5221>\
**Category:** rubyonrails-talk\
**Created:** [November 29, 2006, 7:24pm UTC](https://discuss.rubyonrails.org/t/best-way-to-include-javascript-from-partials/5221 "2006-11-29T19:24:53Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdonnell](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@jdonnell](https://discuss.rubyonrails.org/u/jdonnell)\
**Post date:** [November 29, 2006, 7:24pm UTC](https://discuss.rubyonrails.org/t/best-way-to-include-javascript-from-partials/5221/1 "2006-11-29T19:24:53Z")

</div>

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.
