Page-specific assets in Rails
and the view written:
A more fiddly version that may overcome these problems follows. Instead of a symbol, we include an instance variable in the header to later write to:
<head> ... <%= @even_more_head_content %> </head>
In the view that requires the inclusion, write:
Working through the code, the inclusion variable is initialised if not already. Extra content is then captured and appended to it. "Extra" content may be safely added from several places and will appear in the header. No doubt this could be shortened, if only Ruby would allow pass by reference semantics. A curious site effect is that if you try to include vanilla HTML tags (links, spans, etc.) in the header, they get pushed done into the body of the document and appear at the top of the visible webpage.
Taken from Stack Overflow, although the code as presented there will not work.