Hey guys, In rfacebook, the callback_path variable allows the developer to strip part of the URL off of auto-generated links (link_to). For example, if an app''s canvas pages lead to a certain controller: http://apps.facebook.com/appname/index -> http://appserver.com/controller/index I want the link_to method to prefix the action with ''http://apps.facebook.com/appname/'', automatically stripping out the app server and controller. The rfacebook config variables allows this with callback_path set to ''/controller/''. Is there an equivalent behavior/config for Facebooker? Thanks, Shawn
Hey Shawn, Are you saying that you basically only want one controller to handle all your facebook requests? And that appname == controller? I looked into this scenario and it looks like maybe the code would need to change to handle it. Basically you don''t want to have any relative_root_url and you set the Callback Url in your facebook application settings to the same name as your controller. Something like http://appserver.com/facebook_handler Then create a facebook_handler_controller. And then change the code in facebook_url_rewriting to this def relative_url_root "/#{ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']}" if (parameters[''fb_sig''] && (ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']) ) end This will effectively remove the relative url root. But maybe I am wrong as to what you are trying to do. Dave On Jan 19, 2008 7:23 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote:> Hey guys, > > In rfacebook, the callback_path variable allows the developer to strip part of the URL off of auto-generated links (link_to). For example, if an app''s canvas pages lead to a certain controller: > > http://apps.facebook.com/appname/index > -> http://appserver.com/controller/index > > I want the link_to method to prefix the action with ''http://apps.facebook.com/appname/'', automatically stripping out the app server and controller. The rfacebook config variables allows this with callback_path set to ''/controller/''. > > Is there an equivalent behavior/config for Facebooker? > > Thanks, > Shawn > _______________________________________________ > Facebooker-talk mailing list > Facebooker-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/facebooker-talk >
Hi David, What rfacebook does is perform substitute the controller part of the URL with the app name with a wrapper function around ActionController::Base::url_for. See this file: http://files.rubypub.com/rfacebook-0.9.7/lib/rfacebook_on_rails/controller_extensions.rb if path.starts_with?(self.facebook_callback_path) path.sub!(self.facebook_callback_path, self.facebook_canvas_path) path = "http://apps.facebook.com#{path}" elsif ... Thus it can ensure that any URL''s generated by link_to will point to the facebook app and not include any portion of the server path that is already included in the facebook callback path. We need something like this in Facebooker, too. Shawn On Sat, 19 Jan 2008 20:46:29 -0700, David Clements wrote:> Hey Shawn, > > Are you saying that you basically only want one controller to handle > all your facebook requests? And that appname == controller? > > I looked into this scenario and it looks like maybe the code would > need to change to handle it. Basically you don''t want to have any > relative_root_url and you set the Callback Url in your facebook > application settings to the same name as your controller. > > Something like http://appserver.com/facebook_handler > > Then create a facebook_handler_controller. > > And then change the code in facebook_url_rewriting to this > > def relative_url_root > "/#{ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']}" > if (parameters[''fb_sig''] && > (ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']) > ) > end > > > This will effectively remove the relative url root. > > But maybe I am wrong as to what you are trying to do. > > > Dave > > > > On Jan 19, 2008 7:23 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote: >> Hey guys, >> >> In rfacebook, the callback_path variable allows the developer to >> strip part of the URL off of auto-generated links (link_to). For >> example, if an app''s canvas pages lead to a certain controller: >> >> http://apps.facebook.com/appname/index >> -> http://appserver.com/controller/index >> >> I want the link_to method to prefix the action with >> ''http://apps.facebook.com/appname/'', automatically stripping out the >> app server and controller. The rfacebook config variables allows >> this with callback_path set to ''/controller/''. >> >> Is there an equivalent behavior/config for Facebooker? >> >> Thanks, >> Shawn >> _______________________________________________ >> Facebooker-talk mailing list >> Facebooker-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/facebooker-talk >>
How does Facebooker alter the ActionController::Base class? I see that rfacebook uses an include: ActionController::Base.send(:include, RFacebook::Rails::ControllerExtensions) ActionController::Base.send(:include, RFacebook::Rails::Plugin::ControllerExtensions) I need to do something similar to write the url_for wrapper, so I can rewrite the path returned by url_for. But I want to include the new function in the "right" Facebooker way. Shawn On Sat, 19 Jan 2008 20:46:29 -0700, David Clements wrote:> Hey Shawn, > > Are you saying that you basically only want one controller to handle > all your facebook requests? And that appname == controller? > > I looked into this scenario and it looks like maybe the code would > need to change to handle it. Basically you don''t want to have any > relative_root_url and you set the Callback Url in your facebook > application settings to the same name as your controller. > > Something like http://appserver.com/facebook_handler > > Then create a facebook_handler_controller. > > And then change the code in facebook_url_rewriting to this > > def relative_url_root > "/#{ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']}" > if (parameters[''fb_sig''] && > (ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']) > ) > end > > > This will effectively remove the relative url root. > > But maybe I am wrong as to what you are trying to do. > > > Dave > > > > On Jan 19, 2008 7:23 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote: >> Hey guys, >> >> In rfacebook, the callback_path variable allows the developer to >> strip part of the URL off of auto-generated links (link_to). For >> example, if an app''s canvas pages lead to a certain controller: >> >> http://apps.facebook.com/appname/index >> -> http://appserver.com/controller/index >> >> I want the link_to method to prefix the action with >> ''http://apps.facebook.com/appname/'', automatically stripping out the >> app server and controller. The rfacebook config variables allows >> this with callback_path set to ''/controller/''. >> >> Is there an equivalent behavior/config for Facebooker? >> >> Thanks, >> Shawn >> _______________________________________________ >> Facebooker-talk mailing list >> Facebooker-talk at rubyforge.org >> http://rubyforge.org/mailman/listinfo/facebooker-talk >>
Hey Shawn, The Facebooker way is to set your relative root via ENV["FACEBOOKER_RELATIVE_URL_ROOT"] , this root should have nothing to do with your controller names. For me I make it my app name. The facebooker way to do this is to utilize the rails support for relative root path. This allows for all of your URLs, whether you are a facebook app or not, to have a prefix to the path. Facebooker strips this FACEBOOKER_RELATIVE_ROOT on the way in, and the url rewrite code adds it in for you along with apps.facebook.com. This effects all the urls generated via url_for. After doing this, all of your controllers will generate canvas based urls, whether link_to or url_for. Does that make sense? I am not familiar with rfacebook, so I think I misunderstood your original intent. I will also start documenting some of the code so that some of these answers can be gleaned from a quick read. Dave On Jan 20, 2008 6:15 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote:> How does Facebooker alter the ActionController::Base class? I see that rfacebook uses an include: > > ActionController::Base.send(:include, RFacebook::Rails::ControllerExtensions) > ActionController::Base.send(:include, RFacebook::Rails::Plugin::ControllerExtensions) > > I need to do something similar to write the url_for wrapper, so I can rewrite the path returned by url_for. But I want to include the new function in the "right" Facebooker way. > > Shawn > > On Sat, 19 Jan 2008 20:46:29 -0700, David Clements wrote: > > > Hey Shawn, > > > > Are you saying that you basically only want one controller to handle > > all your facebook requests? And that appname == controller? > > > > I looked into this scenario and it looks like maybe the code would > > need to change to handle it. Basically you don''t want to have any > > relative_root_url and you set the Callback Url in your facebook > > application settings to the same name as your controller. > > > > Something like http://appserver.com/facebook_handler > > > > Then create a facebook_handler_controller. > > > > And then change the code in facebook_url_rewriting to this > > > > def relative_url_root > > "/#{ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']}" > > if (parameters[''fb_sig''] && > > (ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']) > > ) > > end > > > > > > This will effectively remove the relative url root. > > > > But maybe I am wrong as to what you are trying to do. > > > > > > Dave > > > > > > > > On Jan 19, 2008 7:23 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote: > >> Hey guys, > >> > >> In rfacebook, the callback_path variable allows the developer to > >> strip part of the URL off of auto-generated links (link_to). For > >> example, if an app''s canvas pages lead to a certain controller: > >> > >> http://apps.facebook.com/appname/index > >> -> http://appserver.com/controller/index > >> > >> I want the link_to method to prefix the action with > >> ''http://apps.facebook.com/appname/'', automatically stripping out the > >> app server and controller. The rfacebook config variables allows > >> this with callback_path set to ''/controller/''. > >> > >> Is there an equivalent behavior/config for Facebooker? > >> > >> Thanks, > >> Shawn > >> _______________________________________________ > >> Facebooker-talk mailing list > >> Facebooker-talk at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/facebooker-talk > >> >
BTW, the reason I''m pointing the app''s callback path to a specific controller is that the facebook app is an add-on to a regular web app, so the other controllers are serving the standard web app, and I want the facebook app confined to its own controller. So it is not ideal for me to use routes to get apps.facebook.com/appname to redirect to apps.facebook.com/appname/controller/index... Shawn On Sun, 20 Jan 2008 18:30:52 -0700, David Clements wrote:> Hey Shawn, > > The Facebooker way is to set your relative root via > ENV["FACEBOOKER_RELATIVE_URL_ROOT"] , this root should have nothing to > do with your controller names. For me I make it my app name. > > The facebooker way to do this is to utilize the rails support for > relative root path. This allows for all of your URLs, whether you are > a facebook app or not, to have a prefix to the path. Facebooker > strips this FACEBOOKER_RELATIVE_ROOT on the way in, and the url > rewrite code adds it in for you along with apps.facebook.com. This > effects all the urls generated via url_for. > > After doing this, all of your controllers will generate canvas based > urls, whether link_to or url_for. > > Does that make sense? I am not familiar with rfacebook, so I think I > misunderstood your original intent. > > I will also start documenting some of the code so that some of these > answers can be gleaned from a quick read. > > Dave > > On Jan 20, 2008 6:15 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote: >> How does Facebooker alter the ActionController::Base class? I see >> that rfacebook uses an include: >> >> ActionController::Base.send(:include, >> RFacebook::Rails::ControllerExtensions) >> ActionController::Base.send(:include, >> RFacebook::Rails::Plugin::ControllerExtensions) >> >> I need to do something similar to write the url_for wrapper, so I >> can rewrite the path returned by url_for. But I want to include the >> new function in the "right" Facebooker way. >> >> Shawn >> >> On Sat, 19 Jan 2008 20:46:29 -0700, David Clements wrote: >> >>> Hey Shawn, >>> >>> Are you saying that you basically only want one controller to handle >>> all your facebook requests? And that appname == controller? >>> >>> I looked into this scenario and it looks like maybe the code would >>> need to change to handle it. Basically you don''t want to have any >>> relative_root_url and you set the Callback Url in your facebook >>> application settings to the same name as your controller. >>> >>> Something like http://appserver.com/facebook_handler >>> >>> Then create a facebook_handler_controller. >>> >>> And then change the code in facebook_url_rewriting to this >>> >>> def relative_url_root >>> >>> "/#{ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']}" >>> if (parameters[''fb_sig''] && >>> (ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']) >>> ) >>> end >>> >>> >>> This will effectively remove the relative url root. >>> >>> But maybe I am wrong as to what you are trying to do. >>> >>> >>> Dave >>> >>> >>> >>> On Jan 19, 2008 7:23 PM, Shawn Van Ittersum >>> <svicalifornia at gmail.com> wrote: >>>> Hey guys, >>>> >>>> In rfacebook, the callback_path variable allows the developer to >>>> strip part of the URL off of auto-generated links (link_to). For >>>> example, if an app''s canvas pages lead to a certain controller: >>>> >>>> http://apps.facebook.com/appname/index >>>> -> http://appserver.com/controller/index >>>> >>>> I want the link_to method to prefix the action with >>>> ''http://apps.facebook.com/appname/'', automatically stripping out the >>>> app server and controller. The rfacebook config variables allows >>>> this with callback_path set to ''/controller/''. >>>> >>>> Is there an equivalent behavior/config for Facebooker? >>>> >>>> Thanks, >>>> Shawn >>>> _______________________________________________ >>>> Facebooker-talk mailing list >>>> Facebooker-talk at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/facebooker-talk >>>> >>
Hey Shawn, I think I understand and my initial post should address the issue, and I tested it in my dev environment to make sure. Basically you don''t want any relative root url, the current code has a deficiency (IMHO), and the change that I suggested should allow you to avoid the issue that you are having. I''ll wrap it up as a patch and see if the guys want to change it. But to get you going you change the code in facebook_url_rewriting to this def relative_url_root "/#{ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']}" if (parameters[''fb_sig''] && (ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']) ) end And then remove any env variable for FACEBOOKER_RELATIVE_URL_ROOT or FACEBOOK_CANVAS_PATH. Does that make sense? Dave On Jan 20, 2008 7:15 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote:> BTW, the reason I''m pointing the app''s callback path to a specific controller is that the facebook app is an add-on to a regular web app, so the other controllers are serving the standard web app, and I want the facebook app confined to its own controller. So it is not ideal for me to use routes to get apps.facebook.com/appname to redirect to apps.facebook.com/appname/controller/index... > > Shawn > > > On Sun, 20 Jan 2008 18:30:52 -0700, David Clements wrote: > > Hey Shawn, > > > > The Facebooker way is to set your relative root via > > ENV["FACEBOOKER_RELATIVE_URL_ROOT"] , this root should have nothing to > > do with your controller names. For me I make it my app name. > > > > The facebooker way to do this is to utilize the rails support for > > relative root path. This allows for all of your URLs, whether you are > > a facebook app or not, to have a prefix to the path. Facebooker > > strips this FACEBOOKER_RELATIVE_ROOT on the way in, and the url > > rewrite code adds it in for you along with apps.facebook.com. This > > effects all the urls generated via url_for. > > > > After doing this, all of your controllers will generate canvas based > > urls, whether link_to or url_for. > > > > Does that make sense? I am not familiar with rfacebook, so I think I > > misunderstood your original intent. > > > > I will also start documenting some of the code so that some of these > > answers can be gleaned from a quick read. > > > > Dave > > > > On Jan 20, 2008 6:15 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote: > >> How does Facebooker alter the ActionController::Base class? I see > >> that rfacebook uses an include: > >> > >> ActionController::Base.send(:include, > >> RFacebook::Rails::ControllerExtensions) > >> ActionController::Base.send(:include, > >> RFacebook::Rails::Plugin::ControllerExtensions) > >> > >> I need to do something similar to write the url_for wrapper, so I > >> can rewrite the path returned by url_for. But I want to include the > >> new function in the "right" Facebooker way. > >> > >> Shawn > >> > >> On Sat, 19 Jan 2008 20:46:29 -0700, David Clements wrote: > >> > >>> Hey Shawn, > >>> > >>> Are you saying that you basically only want one controller to handle > >>> all your facebook requests? And that appname == controller? > >>> > >>> I looked into this scenario and it looks like maybe the code would > >>> need to change to handle it. Basically you don''t want to have any > >>> relative_root_url and you set the Callback Url in your facebook > >>> application settings to the same name as your controller. > >>> > >>> Something like http://appserver.com/facebook_handler > >>> > >>> Then create a facebook_handler_controller. > >>> > >>> And then change the code in facebook_url_rewriting to this > >>> > >>> def relative_url_root > >>> > >>> "/#{ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']}" > >>> if (parameters[''fb_sig''] && > >>> (ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']) > >>> ) > >>> end > >>> > >>> > >>> This will effectively remove the relative url root. > >>> > >>> But maybe I am wrong as to what you are trying to do. > >>> > >>> > >>> Dave > >>> > >>> > >>> > >>> On Jan 19, 2008 7:23 PM, Shawn Van Ittersum > >>> <svicalifornia at gmail.com> wrote: > >>>> Hey guys, > >>>> > >>>> In rfacebook, the callback_path variable allows the developer to > >>>> strip part of the URL off of auto-generated links (link_to). For > >>>> example, if an app''s canvas pages lead to a certain controller: > >>>> > >>>> http://apps.facebook.com/appname/index > >>>> -> http://appserver.com/controller/index > >>>> > >>>> I want the link_to method to prefix the action with > >>>> ''http://apps.facebook.com/appname/'', automatically stripping out the > >>>> app server and controller. The rfacebook config variables allows > >>>> this with callback_path set to ''/controller/''. > >>>> > >>>> Is there an equivalent behavior/config for Facebooker? > >>>> > >>>> Thanks, > >>>> Shawn > >>>> _______________________________________________ > >>>> Facebooker-talk mailing list > >>>> Facebooker-talk at rubyforge.org > >>>> http://rubyforge.org/mailman/listinfo/facebooker-talk > >>>> > >> >
I hacked a bit and got the rfacebook behavior to work. I''ve probably broken the Facebooker way, so we''ll need to reconcile the changes somehow to make it backward compatible with existing Facebooker apps. Here''s the new sub as I have it: def rewrite_url_with_facebooker(*args) options = args.first.is_a?(Hash) ? args.first : args.last is_link_to_canvas = link_to_canvas?(@request.request_parameters, options) #options[:skip_relative_url_root] ||= !is_link_to_canvas options[:skip_relative_url_root] = true if is_link_to_canvas && !options.has_key?(:host) options[:host] = "apps.facebook.com" end options.delete(:canvas) path = rewrite_url_without_facebooker(*args) facebook_canvas_path = ENV[''FACEBOOKER_RELATIVE_URL_ROOT''] || ENV[''FACEBOOK_CANVAS_PATH''] facebook_callback_path = ENV[''FACEBOOKER_CALLBACK_PATH''] print "path: #{path}\n\n" # for debugging only # replace anything that references the callback with the # Facebook canvas equivalent (apps.facebook.com/*) if path.starts_with?(facebook_callback_path) path.sub!(facebook_callback_path, facebook_canvas_path) path = "http://apps.facebook.com#{path}" elsif "#{path}/".starts_with?(facebook_callback_path) path.sub!(facebook_callback_path.chop, facebook_canvas_path.chop) path = "http://apps.facebook.com#{path}" elsif (path.starts_with?("http://www.facebook.com") or path.starts_with?("https://www.facebook.com")) # be sure that URLs that go to some other Facebook service redirect back to the canvas if path.include?("?") path = "#{path}&canvas=true" else path = "#{path}?canvas=true" end elsif (!path.starts_with?("http://") and !path.starts_with?("https://")) # this will fail here because ''request'' is not defined; need to translate to Facebooker vars # default to a full URL (will link externally) RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to get canvas-friendly URL ("+path+") for ["+options.inspect+"], creating an external URL instead" path = "#{request.protocol}#{request.host}:#{request.port}#{path}" end end Shawn On Sun, 20 Jan 2008 18:30:52 -0700, David Clements wrote:> Hey Shawn, > > The Facebooker way is to set your relative root via > ENV["FACEBOOKER_RELATIVE_URL_ROOT"] , this root should have nothing to > do with your controller names. For me I make it my app name. > > The facebooker way to do this is to utilize the rails support for > relative root path. This allows for all of your URLs, whether you are > a facebook app or not, to have a prefix to the path. Facebooker > strips this FACEBOOKER_RELATIVE_ROOT on the way in, and the url > rewrite code adds it in for you along with apps.facebook.com. This > effects all the urls generated via url_for. > > After doing this, all of your controllers will generate canvas based > urls, whether link_to or url_for. > > Does that make sense? I am not familiar with rfacebook, so I think I > misunderstood your original intent. > > I will also start documenting some of the code so that some of these > answers can be gleaned from a quick read. > > Dave > > On Jan 20, 2008 6:15 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote: >> How does Facebooker alter the ActionController::Base class? I see >> that rfacebook uses an include: >> >> ActionController::Base.send(:include, >> RFacebook::Rails::ControllerExtensions) >> ActionController::Base.send(:include, >> RFacebook::Rails::Plugin::ControllerExtensions) >> >> I need to do something similar to write the url_for wrapper, so I >> can rewrite the path returned by url_for. But I want to include the >> new function in the "right" Facebooker way. >> >> Shawn >> >> On Sat, 19 Jan 2008 20:46:29 -0700, David Clements wrote: >> >>> Hey Shawn, >>> >>> Are you saying that you basically only want one controller to handle >>> all your facebook requests? And that appname == controller? >>> >>> I looked into this scenario and it looks like maybe the code would >>> need to change to handle it. Basically you don''t want to have any >>> relative_root_url and you set the Callback Url in your facebook >>> application settings to the same name as your controller. >>> >>> Something like http://appserver.com/facebook_handler >>> >>> Then create a facebook_handler_controller. >>> >>> And then change the code in facebook_url_rewriting to this >>> >>> def relative_url_root >>> >>> "/#{ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']}" >>> if (parameters[''fb_sig''] && >>> (ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']) >>> ) >>> end >>> >>> >>> This will effectively remove the relative url root. >>> >>> But maybe I am wrong as to what you are trying to do. >>> >>> >>> Dave >>> >>> >>> >>> On Jan 19, 2008 7:23 PM, Shawn Van Ittersum >>> <svicalifornia at gmail.com> wrote: >>>> Hey guys, >>>> >>>> In rfacebook, the callback_path variable allows the developer to >>>> strip part of the URL off of auto-generated links (link_to). For >>>> example, if an app''s canvas pages lead to a certain controller: >>>> >>>> http://apps.facebook.com/appname/index >>>> -> http://appserver.com/controller/index >>>> >>>> I want the link_to method to prefix the action with >>>> ''http://apps.facebook.com/appname/'', automatically stripping out the >>>> app server and controller. The rfacebook config variables allows >>>> this with callback_path set to ''/controller/''. >>>> >>>> Is there an equivalent behavior/config for Facebooker? >>>> >>>> Thanks, >>>> Shawn >>>> _______________________________________________ >>>> Facebooker-talk mailing list >>>> Facebooker-talk at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/facebooker-talk >>>> >>
Hey Shawn, FYI: I played around with this some more today with the application that has the same requirements as yours: Canvas path is http://apps.facebook.com/travelerstable Callback URL is http://www.travelerstable.com/facebook Controller is facebook_controller, and the is only one controller that handles all the facebook requests. This is the same sort of setup that you have right? I was able to get facebooker to work by implementing the previous mentioned change that allows AbstractRequest.relative_root_url to return nil if it is not set and by adding this route. map.canvas_page_base("#{ENV["FACEBOOK_APP_NAME"]}/:action/:id", :controller => ''facebook'') I remember you saying that you didn''t really like this approach, but I thought I would try it out anyway. I would like to take a poll to understand how many people fall into one of these four use cases. 1) Callback path and canvas path have the same ending. 2) Callback path and canvas path have a different ending and app uses multiple controllers to handle facebook requests 3) Callback path and canvas path have a different ending and app use one controller to handle all facebook requests ( This is what Shawn and I have been discussing. ) 4) Callback path only contains the host portion. (ex. http://www.example.com/ ) I hope that is clear, did I cover them all? Dave On Jan 20, 2008 8:14 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote:> I hacked a bit and got the rfacebook behavior to work. I''ve probably broken the Facebooker way, so we''ll need to reconcile the changes somehow to make it backward compatible with existing Facebooker apps. > > Here''s the new sub as I have it: > > def rewrite_url_with_facebooker(*args) > options = args.first.is_a?(Hash) ? args.first : args.last > is_link_to_canvas = link_to_canvas?(@request.request_parameters, options) > #options[:skip_relative_url_root] ||= !is_link_to_canvas > options[:skip_relative_url_root] = true > if is_link_to_canvas && !options.has_key?(:host) > options[:host] = "apps.facebook.com" > end > options.delete(:canvas) > > path = rewrite_url_without_facebooker(*args) > > facebook_canvas_path = ENV[''FACEBOOKER_RELATIVE_URL_ROOT''] || ENV[''FACEBOOK_CANVAS_PATH''] > facebook_callback_path = ENV[''FACEBOOKER_CALLBACK_PATH''] > > print "path: #{path}\n\n" # for debugging only > > # replace anything that references the callback with the > # Facebook canvas equivalent (apps.facebook.com/*) > if path.starts_with?(facebook_callback_path) > path.sub!(facebook_callback_path, facebook_canvas_path) > path = "http://apps.facebook.com#{path}" > elsif "#{path}/".starts_with?(facebook_callback_path) > path.sub!(facebook_callback_path.chop, facebook_canvas_path.chop) > path = "http://apps.facebook.com#{path}" > elsif (path.starts_with?("http://www.facebook.com") or path.starts_with?("https://www.facebook.com")) > # be sure that URLs that go to some other Facebook service redirect back to the canvas > if path.include?("?") > path = "#{path}&canvas=true" > else > path = "#{path}?canvas=true" > end > elsif (!path.starts_with?("http://") and !path.starts_with?("https://")) > # this will fail here because ''request'' is not defined; need to translate to Facebooker vars > > # default to a full URL (will link externally) > RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to get canvas-friendly URL ("+path+") for ["+options.inspect+"], creating an external URL instead" > path = "#{request.protocol}#{request.host}:#{request.port}#{path}" > end > end > > Shawn > > > On Sun, 20 Jan 2008 18:30:52 -0700, David Clements wrote: > > Hey Shawn, > > > > The Facebooker way is to set your relative root via > > ENV["FACEBOOKER_RELATIVE_URL_ROOT"] , this root should have nothing to > > do with your controller names. For me I make it my app name. > > > > The facebooker way to do this is to utilize the rails support for > > relative root path. This allows for all of your URLs, whether you are > > a facebook app or not, to have a prefix to the path. Facebooker > > strips this FACEBOOKER_RELATIVE_ROOT on the way in, and the url > > rewrite code adds it in for you along with apps.facebook.com. This > > effects all the urls generated via url_for. > > > > After doing this, all of your controllers will generate canvas based > > urls, whether link_to or url_for. > > > > Does that make sense? I am not familiar with rfacebook, so I think I > > misunderstood your original intent. > > > > I will also start documenting some of the code so that some of these > > answers can be gleaned from a quick read. > > > > Dave > > > > On Jan 20, 2008 6:15 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote: > >> How does Facebooker alter the ActionController::Base class? I see > >> that rfacebook uses an include: > >> > >> ActionController::Base.send(:include, > >> RFacebook::Rails::ControllerExtensions) > >> ActionController::Base.send(:include, > >> RFacebook::Rails::Plugin::ControllerExtensions) > >> > >> I need to do something similar to write the url_for wrapper, so I > >> can rewrite the path returned by url_for. But I want to include the > >> new function in the "right" Facebooker way. > >> > >> Shawn > >> > >> On Sat, 19 Jan 2008 20:46:29 -0700, David Clements wrote: > >> > >>> Hey Shawn, > >>> > >>> Are you saying that you basically only want one controller to handle > >>> all your facebook requests? And that appname == controller? > >>> > >>> I looked into this scenario and it looks like maybe the code would > >>> need to change to handle it. Basically you don''t want to have any > >>> relative_root_url and you set the Callback Url in your facebook > >>> application settings to the same name as your controller. > >>> > >>> Something like http://appserver.com/facebook_handler > >>> > >>> Then create a facebook_handler_controller. > >>> > >>> And then change the code in facebook_url_rewriting to this > >>> > >>> def relative_url_root > >>> > >>> "/#{ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']}" > >>> if (parameters[''fb_sig''] && > >>> (ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']) > >>> ) > >>> end > >>> > >>> > >>> This will effectively remove the relative url root. > >>> > >>> But maybe I am wrong as to what you are trying to do. > >>> > >>> > >>> Dave > >>> > >>> > >>> > >>> On Jan 19, 2008 7:23 PM, Shawn Van Ittersum > >>> <svicalifornia at gmail.com> wrote: > >>>> Hey guys, > >>>> > >>>> In rfacebook, the callback_path variable allows the developer to > >>>> strip part of the URL off of auto-generated links (link_to). For > >>>> example, if an app''s canvas pages lead to a certain controller: > >>>> > >>>> http://apps.facebook.com/appname/index > >>>> -> http://appserver.com/controller/index > >>>> > >>>> I want the link_to method to prefix the action with > >>>> ''http://apps.facebook.com/appname/'', automatically stripping out the > >>>> app server and controller. The rfacebook config variables allows > >>>> this with callback_path set to ''/controller/''. > >>>> > >>>> Is there an equivalent behavior/config for Facebooker? > >>>> > >>>> Thanks, > >>>> Shawn > >>>> _______________________________________________ > >>>> Facebooker-talk mailing list > >>>> Facebooker-talk at rubyforge.org > >>>> http://rubyforge.org/mailman/listinfo/facebooker-talk > >>>> > >> >
Hey Dave, Thanks for looking into this and other alternative approaches to this case. I appreciate the ideas and proposed workarounds. However, it would be great if Facebooker offered the same flexibility of configuration as rfacebook does, so developers who started there do not have to change the routing of their applications to use Facebooker. Of course I would not want to impact existing Facebooker apps, but I believe it is possible to support the URL rewriting done by rfacebook in a way that is backward compatible with existing Facebooker configs. I believe the rfacebook solution handles all of the cases Dave is polling about now, and for any developers who want to use the Facebooker framework to handle any of these use cases, it is much easier to explain how to set the callback_path (which is already set on the Facebook Developers app) than to explain the various routing solutions on a case-by-case basis. And the callback_path rewriting solution ensures that the routing exceptions will not need revisited, relearned, and modified should the design of an application change. One need only change the callback_path or appname as necessary, which is extremely simple, making app changes much easier to implement. With our progress last night, we are very close and should be able to support the callback_path URL rewrite by the end of the week. Shawn On Mon, 21 Jan 2008 21:05:17 -0700, David Clements wrote:> Hey Shawn, > > FYI: > I played around with this some more today with the application that > has the same requirements as yours: > > Canvas path is http://apps.facebook.com/travelerstable > Callback URL is http://www.travelerstable.com/facebook > > Controller is facebook_controller, and the is only one controller that > handles all the facebook requests. This is the same sort of setup > that you have right? > > I was able to get facebooker to work by implementing the previous > mentioned change that allows AbstractRequest.relative_root_url to > return nil if it is not set and by adding this route. > > map.canvas_page_base("#{ENV["FACEBOOK_APP_NAME"]}/:action/:id", > :controller => ''facebook'') > > I remember you saying that you didn''t really like this approach, but I > thought I would try it out anyway. > > > > I would like to take a poll to understand how many people fall into > one of these four use cases. > > > 1) Callback path and canvas path have the same ending. > 2) Callback path and canvas path have a different ending and app uses > multiple controllers to handle facebook requests > 3) Callback path and canvas path have a different ending and app use > one controller to handle all facebook requests ( This is what Shawn > and I have been discussing. ) > 4) Callback path only contains the host portion. (ex. > http://www.example.com/ ) > > I hope that is clear, did I cover them all? > Dave > > > > > On Jan 20, 2008 8:14 PM, Shawn Van Ittersum <svicalifornia at gmail.com> wrote: >> I hacked a bit and got the rfacebook behavior to work. I''ve >> probably broken the Facebooker way, so we''ll need to reconcile the >> changes somehow to make it backward compatible with existing >> Facebooker apps. >> >> Here''s the new sub as I have it: >> >> def rewrite_url_with_facebooker(*args) >> options = args.first.is_a?(Hash) ? args.first : args.last >> is_link_to_canvas = >> link_to_canvas?(@request.request_parameters, options) >> #options[:skip_relative_url_root] ||= !is_link_to_canvas >> options[:skip_relative_url_root] = true >> if is_link_to_canvas && !options.has_key?(:host) >> options[:host] = "apps.facebook.com" >> end >> options.delete(:canvas) >> >> path = rewrite_url_without_facebooker(*args) >> >> facebook_canvas_path = ENV[''FACEBOOKER_RELATIVE_URL_ROOT''] || >> ENV[''FACEBOOK_CANVAS_PATH''] >> facebook_callback_path = ENV[''FACEBOOKER_CALLBACK_PATH''] >> >> print "path: #{path}\n\n" # for debugging only >> >> # replace anything that references the callback with the >> # Facebook canvas equivalent (apps.facebook.com/*) >> if path.starts_with?(facebook_callback_path) >> path.sub!(facebook_callback_path, facebook_canvas_path) >> path = "http://apps.facebook.com#{path}" >> elsif "#{path}/".starts_with?(facebook_callback_path) >> path.sub!(facebook_callback_path.chop, facebook_canvas_path.chop) >> path = "http://apps.facebook.com#{path}" >> elsif (path.starts_with?("http://www.facebook.com") or >> path.starts_with?("https://www.facebook.com")) >> # be sure that URLs that go to some other Facebook service >> redirect back to the canvas >> if path.include?("?") >> path = "#{path}&canvas=true" >> else >> path = "#{path}?canvas=true" >> end >> elsif (!path.starts_with?("http://") and >> !path.starts_with?("https://")) >> # this will fail here because ''request'' is not defined; need >> to translate to Facebooker vars >> >> # default to a full URL (will link externally) >> RAILS_DEFAULT_LOGGER.debug "** RFACEBOOK INFO: failed to get >> canvas-friendly URL ("+path+") for ["+options.inspect+"], creating >> an external URL instead" >> path = "#{request.protocol}#{request.host}:#{request.port}#{path}" >> end >> end >> >> Shawn >> >> >> On Sun, 20 Jan 2008 18:30:52 -0700, David Clements wrote: >>> Hey Shawn, >>> >>> The Facebooker way is to set your relative root via >>> ENV["FACEBOOKER_RELATIVE_URL_ROOT"] , this root should have nothing to >>> do with your controller names. For me I make it my app name. >>> >>> The facebooker way to do this is to utilize the rails support for >>> relative root path. This allows for all of your URLs, whether you are >>> a facebook app or not, to have a prefix to the path. Facebooker >>> strips this FACEBOOKER_RELATIVE_ROOT on the way in, and the url >>> rewrite code adds it in for you along with apps.facebook.com. This >>> effects all the urls generated via url_for. >>> >>> After doing this, all of your controllers will generate canvas based >>> urls, whether link_to or url_for. >>> >>> Does that make sense? I am not familiar with rfacebook, so I think I >>> misunderstood your original intent. >>> >>> I will also start documenting some of the code so that some of these >>> answers can be gleaned from a quick read. >>> >>> Dave >>> >>> On Jan 20, 2008 6:15 PM, Shawn Van Ittersum >>> <svicalifornia at gmail.com> wrote: >>>> How does Facebooker alter the ActionController::Base class? I see >>>> that rfacebook uses an include: >>>> >>>> ActionController::Base.send(:include, >>>> RFacebook::Rails::ControllerExtensions) >>>> ActionController::Base.send(:include, >>>> RFacebook::Rails::Plugin::ControllerExtensions) >>>> >>>> I need to do something similar to write the url_for wrapper, so I >>>> can rewrite the path returned by url_for. But I want to include the >>>> new function in the "right" Facebooker way. >>>> >>>> Shawn >>>> >>>> On Sat, 19 Jan 2008 20:46:29 -0700, David Clements wrote: >>>> >>>>> Hey Shawn, >>>>> >>>>> Are you saying that you basically only want one controller to handle >>>>> all your facebook requests? And that appname == controller? >>>>> >>>>> I looked into this scenario and it looks like maybe the code would >>>>> need to change to handle it. Basically you don''t want to have any >>>>> relative_root_url and you set the Callback Url in your facebook >>>>> application settings to the same name as your controller. >>>>> >>>>> Something like http://appserver.com/facebook_handler >>>>> >>>>> Then create a facebook_handler_controller. >>>>> >>>>> And then change the code in facebook_url_rewriting to this >>>>> >>>>> def relative_url_root >>>>> >>>>> "/#{ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']}" >>>>> if (parameters[''fb_sig''] && >>>>> (ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']||ENV[''FACEBOOK_CANVAS_PATH'']) >>>>> ) >>>>> end >>>>> >>>>> >>>>> This will effectively remove the relative url root. >>>>> >>>>> But maybe I am wrong as to what you are trying to do. >>>>> >>>>> >>>>> Dave >>>>> >>>>> >>>>> >>>>> On Jan 19, 2008 7:23 PM, Shawn Van Ittersum >>>>> <svicalifornia at gmail.com> wrote: >>>>>> Hey guys, >>>>>> >>>>>> In rfacebook, the callback_path variable allows the developer to >>>>>> strip part of the URL off of auto-generated links (link_to). For >>>>>> example, if an app''s canvas pages lead to a certain controller: >>>>>> >>>>>> http://apps.facebook.com/appname/index >>>>>> -> http://appserver.com/controller/index >>>>>> >>>>>> I want the link_to method to prefix the action with >>>>>> ''http://apps.facebook.com/appname/'', automatically stripping out the >>>>>> app server and controller. The rfacebook config variables allows >>>>>> this with callback_path set to ''/controller/''. >>>>>> >>>>>> Is there an equivalent behavior/config for Facebooker? >>>>>> >>>>>> Thanks, >>>>>> Shawn >>>>>> _______________________________________________ >>>>>> Facebooker-talk mailing list >>>>>> Facebooker-talk at rubyforge.org >>>>>> http://rubyforge.org/mailman/listinfo/facebooker-talk >>>>>> >>>> >>