Skip to content

Instantly share code, notes, and snippets.

@garethrees
Created November 24, 2012 22:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garethrees/4141674 to your computer and use it in GitHub Desktop.
Save garethrees/4141674 to your computer and use it in GitHub Desktop.
Rails Shared Templates
<%#
# Renders Google Analytics tracking script
#
# Example
#
# <%= render 'shared/analytics', ua_code: 'UA-XXXXXX-X' %>
#
#%>
<% if Rails.env.production? %>
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker(<%= ua_code.to_s %>);
pageTracker._trackPageview();
} catch(err) {}</script>
<% end %>
<%#
# Renders form validation messages
#
# Example
#
# <%= form_for @mymodel do |f| %>
# <%= render 'shared/error_messages', target: @model %>
# # ...
# <% end %>
#
#%>
<% if target.errors.any? %>
<div id="errorExplanation">
<h2><%= pluralize(target.errors.count, 'error') %> prohibited this record from being saved:</h2>
<ul>
<% target.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%#
# Renders flash messages
#
# Example
#
# <%= render 'shared/flash', object: flash %>
#
#%>
<% unless flash.blank? -%>
<% flash.each do |name, msg| -%>
<%= content_tag :div, msg, class: "message message-#{ name }" %>
<% end -%>
<% end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment