Skip to content

Instantly share code, notes, and snippets.

@yorzi
Created May 10, 2013 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorzi/5554586 to your computer and use it in GitHub Desktop.
Save yorzi/5554586 to your computer and use it in GitHub Desktop.
share to facebook with necessary information attached by default form.
<% content_for :html_head_content do %>
<meta property="og:title" content="<%= @post.title %>"/>
<meta property="og:type" content="website"/>
<meta property="og:site_name" content="sample.com"/>
<% if Rails.env == 'production' %>
<meta property="og:image" content="http://sample.com/assets/logo.png"/>
<% else %>
<meta property="og:image" content="http://sample.com/logo.png"/>
<% end %>
<meta property="og:description" content="<%= strip_tags(@post.excerpt).strip[0, 200] %>"/>
<!-- Twitter Card -->
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@sample">
<meta name="twitter:creator" content="@<%= @post.user.twitter %>">
<meta name="twitter:url" content="http://www.sample.com<%= post_link(@post) %>">
<meta name="twitter:title" content="<%= @post.title %>">
<meta name="twitter:description" content="<%= strip_tags(@post.excerpt).strip[0, 200] %>">
<% if @post.image? %>
<meta name="twitter:image" content="<%= @post.image %>">
<% end %>
<% unless Rails.env == 'production' %>
<script>
var disqus_developer = 1; // developer mode is on
</script>
<% end %>
<% end %>
<% content_for :javascripts do %>
<script type= 'text/javascript'>
$('.fb_share').live('click', function(event) {
var width = 575,
height = 400,
left = ($(window).width() - width) / 2,
top = ($(window).height() - height) / 2,
url = this.href,
opts = 'status=1' +
',width=' + width +
',height=' + height +
',top=' + top +
',left=' + left;
window.open("http://www.facebook.com/sharer.php?u=<%= url_for(:action => params[:action], :controller => params[:controller], :only_path => false, :protocol => 'http') %>&t=<%= @post.title %>", 'Facebook', opts);
return false;
});
</script>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment