I have a head_tracking_code
and bottom_tracking_code
. The content needs to be invisible in the view. But when you inspect the HTML it needs to show.
The content that will be in them will be set in the CMS. Just assume that anything can be in these tracking codes, so something crazy like 23142j3rqjefapisodfhp435
.
Problem. @page is set. The head and bottom tracking codes aren't showing when i inspect the HTML. What is wrong? How do i fix this?
Please refer to content_for
in application.html.erb
pages_controller.rb
def set_tracking_codes
return unless @page
view_context.content_for(:head_tracking_code, @page.head_tracking_code.to_s.html_safe)
view_context.content_for(:bottom_tracking_code, @page.bottom_tracking_code.to_s.html_safe)
end
__________________
application.html.erb
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<% if Rails.env.production? || Rails.env.staging? %>
<% if Settings.head_snippet.present? %>
<%= Settings.head_snippet.html_safe %>
<% end %>
<% end %>
<title><%= content_for(:title).presence || 'Learn to Read and Spell with LiteracyPlanet' %> - LiteracyPlanet</title>
<meta name="description" http-equiv="description" content="<%= content_for(:meta_description) || 'Online resource with 15,000+ fun and interactive literacy games for children of all abilities aged 4-15yrs.'%>"/>
<meta name="keywords" http-equiv="keywords" content="<%= content_for(:meta_keywords) || 'Learn to read, learn to spell, reading exercises, spelling exercises, comprehension exercises, grammar exercises, literacy program, reading program, spelling program, grammar program, reading, spelling, comprehension, grammar, phonics' %>"/>
<meta property="og:image" content="//lp-static-assets.s3.amazonaws.com/images/social-image.png">
<meta property="og:description" content="<%= content_for(:meta_description) || 'Online resource with 15,000+ fun and interactive literacy games for children of all abilities aged 4-15yrs.'%>"/>
<meta property="og:site_name" content="LiteracyPlanet" />
<meta name="twitter:card" content="summary">
<meta name="twitter:creator" content="@literacyplanet">
<%= auto_discovery_link_tag :rss, "#{ENV['WWW_SITE_HOST']}/blog.rss" %>
<%= favicon_link_tag 'favicon.ico' %>
<!--[if lte IE 8]>
<%= gzip_stylesheet_link_tag "/assets/application-old-ie.css", media: "all" %>
<![endif]-->
<!--[if gt IE 8]><!-->
<%= gzip_stylesheet_link_tag "/assets/application.css", media: "all", "data-turbolinks-track" => true %>
<!--<![endif]-->
<%= gzip_javascript_include_tag "/assets/javascripts/site.js", "jwplayer.js", "data-turbolinks-track" => true %>
<script type="text/javascript">jwplayer.key="0UG0dyoFym7xbYN1zHYPwqH43ezwry5Zy808mg==";</script>
<%= csrf_meta_tags %>
<%= content_for :head_tracking_code %>
</head>
<body class="<%= yield (:body_class) %>">
<!--[if lt IE 8]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<%= yield %>
<% unless request.path.in?(%w(/freetrial /twelvemonthoffer /freetrialwm)) %>
<%= render footer_partial %>
<% end %>
<% if Rails.env.production? %>
<%= render 'layouts/adroll' %>
<script type="text/javascript">
(function(i,s,o,g,r) {
i['GoogleAnalyticsObject']=r;
i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments);
}
i[r].l=1*new Date();
$.externalScript(g).done(function(script, textStatus) {
if(typeof i[r] == 'undefined') {
console.log('Problem. GA file not loaded');
}
});
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-58399625-1', 'auto');
ga('send', 'pageview');
</script>
<% end %>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-552f341e1bf30a80" async="async"></script>
<%= content_for :bottom_tracking_code %>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire