I'm trying to place some 3rd party script files outside of the body tag (per the 3rd party's request) in my Rails app (Rails 4.0.0, Ruby 2.1.1). I cannot get this to work for my application.html file (neither in HAML nor ERB).
HAML:
%body
= yield
%script
:javascript
ERB:
<body>
<%= yield %>
</body>
<script>
...
</script>
Whether I use ERB or HAML, the resulting live page still puts this script tag INSIDE the body tag at the end rather than outside of it. Anyone have any insight as to whether this is Rails' behavior and if it's specific to Rails 4? Or could it be something the browser is doing outside of Rails?
Updated: application.html.haml file in question (ENV variables resolve without issue):
!!!
%html{"xmlns" => "http://www.w3.org/1999/xhtml", "xmlns:fb" => "http://ogp.me/ns/fb#"}
%head
/ several meta tags
%title= content_for?(:title) ? yield(:title) : "Title"
/ favicon image links
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= javascript_include_tag "application", "data-turbolinks-track" => true
= javascript_include_tag "vendor/modernizr"
= csrf_meta_tags
%script{src: "//cdn.optimizely.com/js/---------.js"}
%body
= yield
%script
:javascript
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', "#{ENV['GA_ID']}", "#{ENV['GA_LABEL']}");
ga('require', 'displayfeatures');
// Optimizely Universal Analytics Integration
window.optimizely = window.optimizely || [];
window.optimizely.push("activateUniversalAnalytics");
ga('send', 'pageview');
/* <![CDATA[ */
var google_conversion_id = ---------;
var google_custom_params = window.google_tag_params;
var google_remarketing_only = true;
Thanks