Skip to content

Instantly share code, notes, and snippets.

@libin
Forked from nicalpi/helper.rb
Created October 5, 2011 20:27
Show Gist options
  • Save libin/1265595 to your computer and use it in GitHub Desktop.
Save libin/1265595 to your computer and use it in GitHub Desktop.
Share with facebook url, with summary and title but no need of OG Data
def share_with_facebook_url(opts)
# Generates an url that will 'share with Facebook', and can includes title, url, summary, images without need of OG data.
#
# URL generate will be like
# http://www.facebook.com/sharer.php?s=100&p[title]=We also do cookies&p[url]=http://www.wealsodocookies.com&p[images][0]=http://www.wealsodocookies.com/images/logo.jpg&p[summary]=Super developer company
#
# For this you'll need to pass the options as
#
# { :url => "http://www.wealsodocookies.com",
# :title => "We also do cookies",
# :images => {0 => "http://imagelink"} # You can have multiple images here
# :summary => "My summary here"
# }
url = "http://www.facebook.com/sharer.php?s=100"
parameters = []
opts.each do |k,v|
key = "p[#{k}]"
if v.is_a? Hash
v.each do |sk, sv|
parameters << "#{key}[#{sk}]=#{sv}"
end
else
parameters << "#{key}=#{v}"
end
end
url + parameters.join("&")
end
= link_to "Share with facebook", share_with_facebook_url({ :url => "http://www.wealsodocookies.com",
:title => "Freelance Rails developer",
:images => {0 => "http://wealsodocookies.com/images/logo.png"},
:summary => "Pragmatic Ruby on Rails development company" })
@AaronHarris
Copy link

where should we put the helper.rb file in the rails app?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment