Skip to content

Instantly share code, notes, and snippets.

@johnnyeric
Last active December 12, 2015 05:29
Show Gist options
  • Select an option

  • Save johnnyeric/4722324 to your computer and use it in GitHub Desktop.

Select an option

Save johnnyeric/4722324 to your computer and use it in GitHub Desktop.
Ruby on Rails helper methods for creating social buttons at the view
#Gets the url, the width and height like integer.
def facebook_button(url,width,height)
"<iframe src=\"http://www.facebook.com/plugins/like.php?href=#{url}&;layout=standard&<br>
show_faces=false&width=380&action=like&colorscheme=light&height=#{width}&locale=pt_BR\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:#{width}px; height:#{height}px;\" allowTransparency=\"true\"></iframe>".html_safe
end
#gets the actual url
def twitter_button
"<a href=\"https://twitter.com/share\" class=\"twitter-share-button\" data-lang=\"pt\">Tweetar</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=\"//platform.twitter.com/widgets.js\";fjs.parentNode.insertBefore(js,fjs);}}(document,\"script\",\"twitter-wjs\");</script>".html_safe
end
def gplus_button(url)
"<!-- Place this tag where you want the +1 button to render. -->
<div class=\"g-plusone\" data-href=\"#{url}\"></div>
<!-- Place this tag after the last +1 button tag. -->
<script type=\"text/javascript\">
window.___gcfg = {lang: 'pt-BR'};
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>".html_safe
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment