Skip to content

Instantly share code, notes, and snippets.

@arvindhsukumar
Created December 9, 2011 08:56
Show Gist options
  • Save arvindhsukumar/1450798 to your computer and use it in GitHub Desktop.
Save arvindhsukumar/1450798 to your computer and use it in GitHub Desktop.
Facebook Feed Dialog Helper for Rails
# app/helpers/application_helper.rb
# In your View, simply call fb_share with options. app_id and redirect_uri are mandatory.
# For more details, please see http://www.behindtechlines.com/2011/12/09/facebook-feed-dialog-rails/
module ApplicationHelper
def fb_share(app_id, redirect_uri, opts={})
o = {:text => 'Share',
:name => '',
:display => '',
:caption => '',
:description => '',
:link => '',
:picture => '',
:source => '',
:properties => {},
:actions => {}}.merge!(opts)
opts_array = []
opts.each do |key, value|
case
when key.to_s == 'properties'
@prop = value.to_json
when key.to_s == 'actions'
@action = value.to_json
else
opts_array.push("#{key}=#{value}")
end
end
url = "http://www.facebook.com/dialog/feed?app_id=#{app_id}&redirect_uri=#{redirect_uri}&#{opts_array.join("&")}&properties=#{@prop}&actions=#{@action}"
link_to("#{o[:text]}", url)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment