I have a partial that requires some related script, so I want to append those javascript include tags to the header whenever the partial is used. So I did:
# app/assets/javascripts/tricky_js.js.coffee
alert "I've been required!!"
# app/views/layouts/application.slim
head
# stuff...
= yield :head
body
= yield
# app/views/shared/_tricky_partial.slim
content_for :head do
= javascript_include_tag :tricky_js
p Bleh
# app/views/shared/unrelated_view.slim
= render 'shared/tricky_partial'
= render 'shared/tricky_partial'
= render 'shared/tricky_partial'
Which of course causes the javascript tag to be appended 3 times and therefore to run alert("I've been required!!") 3 times. How to append the script only once?