-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
= 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" }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where should we put the helper.rb file in the rails app?