sudara
2008-Jan-25 22:09 UTC
[Facebooker-talk] More on routing, relative_root and facebooker
Hey there! I would like the discussion to continue on how facebooker handles routes, as it appears that there is an unsolved issue. Mike, I read your recent reply involving setting facebook''s callback_path to the root of the rails app, and adding a route to catch all calls to the app root where canvas => true. I just want to point out this is counterintuitive to some folks and I didn''t actually get what you really meant until i started writing this. Still my brain is confused, and I have no idea what the ideal is for how facebooker is supposed to work regarding routing. So, I''ll finish writing it so that maybe it helps someone else and again puts it out there that something is funky, at least to folks wanting to do have a part of their app be facebook, but not all of it. Here is why people like me are running into issues. You build a rails app. All is fine and dandy. You want to expose a few controller/actions to facebook, and so you install facebooker. I define my facebook callback_path to be ''facebook'' then facebook should always be hitting: http://mydomain.com/facebook Great. Next, I want to next define routes to catch those calls and render appropriately. I would use map.facebook_resouces, except I can''t pass any options in (for example a prefix ''facebook'' or a different controller name from a route name) For fun, I take an hour and experiment and rewrite the facebook routing stuff to allow it to take options. I get it working great...but still, there was this screwy thing with urls looking like this in canvas: http://apps.facebook.com/appname/facebook/... and therefore hitting the rails routing as: http://mydomain.com/facebook/facebook/.... Ok, so then I try a manual route, just to try and get it working: map.facebook_accounts ''/facebook/:action/:id'', :controller => ''facebook_accounts'' Same deal, the first hit onto facebook is fine, but subsequent calls are wacky. My rails app seems to be working against me. The routes I dictate in routes.rb are not being listened to. There is magic going on that isn''t helping me out, but making things tougher. (What makes matters worse is that people migrating from rFacebook are used to being more or less in control of their routes and probably have a different thinking cap on). So then I read Mike''s latest post, and I say ''ok....make a conditional- on-canvas route for the base route of the app.'' I''m sketched out because I don''t really want my app being hit at the base or to define a route at the app root - I have 90% of my non-facebook stuff running off the root and want the facebook stuff namespaced. I try it anyway... I set my facebook callback url to http://mydomain.com # somewhere in config/initializers ENV[''FACEBOOKER_RELATIVE_URL_ROOT''] = '''' # in routes.rb map.facebook_accounts '''', :controller => ''facebook_accounts'', :condition => {:canvas => true} Ok, that breaks everything. My normal routes no longer function, nor do my helpers for those routes. After the first day of working with facebooker from my perspective, I think the following would be helpful: a) rewrite map.facebook_resources to handle options so people have a bit more flexibility (also add the GET/POST conditions to the routes) b) make it crystal clear somewhere in the docs that by default there is rewriting going on FOR you while in-canvas. I''m tempted to try out Shawns recent rewrite of the url_rewrite thing. Is there openness to a patch being accepted? still not up and running, but still trying, sudara
Mike Mangino
2008-Jan-25 23:31 UTC
[Facebooker-talk] More on routing, relative_root and facebooker
Sudara, I see a couple of issues here. First map.facebook_resources is deprecated. Use map.resources instead The second is that you set your facebook callback path to /facebook. Just leave it as http://mydomain.com/ Facebooker was built so that you can just specify your server root as the callback path. I know this isn''t well documented. I''d love to have patches to fix the documentation. If you include a controller name or a namespace name in your callback path, it makes it very difficult to have multiple environments (dev and prod) and also multiple developers. Here''s how I set things up: in production.rb ENV[''FACEBOOK_CANVAS_PATH''] = ''growing'' # the old name was FACEBOOKER_RELATIVE_URL_ROOT, that was too closely tied to the implementation ActionController::Base.asset_host="http://growing.elevatedrails.com" The main page from Facebook gets the route: map.connect '''', :controller => ''gifts'', :action => ''new'' We have other routes like: map.resources :users, :member => { :profile => :any } map.resources :gifts ... In short, once you add a couple of lines to your environment file, you''ve got a completely normal rails app. If you want to show different information based upon whether the request comes from facebook or not, you do the same thing you would do with a multi-domain app: map.connect '''', :controller => ''gifts'', :action => ''new'', :conditions=>{:canvas=>true} map.connect '''', :controller => ''marketing'', :action => ''index'' compare this to a multidomain site I run: map.connect '''', :controller => ''guide'', :conditions=>{:host=>/guide/} map.connect '''', :controller => ''home'', :action => ''index'' My main goal in building the rails integration of Facebooker this way is to make it identical to running a normal rails application. I want to be able to run a completely facebook app basically out of the box. I want to be able to use respond_to to render different content for Facebook and non-fb users. Mike On Jan 25, 2008, at 4:09 PM, sudara wrote:> Hey there! > > I would like the discussion to continue on how facebooker handles > routes, as it appears that there is an unsolved issue. > > Mike, I read your recent reply involving setting facebook''s > callback_path to the root of the rails app, and adding a route to > catch all calls to the app root where canvas => true. > > I just want to point out this is counterintuitive to some folks and I > didn''t actually get what you really meant until i started writing > this. Still my brain is confused, and I have no idea what the ideal is > for how facebooker is supposed to work regarding routing. So, I''ll > finish writing it so that maybe it helps someone else and again puts > it out there that something is funky, at least to folks wanting to do > have a part of their app be facebook, but not all of it. > > Here is why people like me are running into issues. > > You build a rails app. All is fine and dandy. You want to expose a few > controller/actions to facebook, and so you install facebooker. > > I define my facebook callback_path to be ''facebook'' then facebook > should always be hitting: > > http://mydomain.com/facebook > > Great. Next, I want to next define routes to catch those calls and > render appropriately. > > I would use map.facebook_resouces, except I can''t pass any options in > (for example a prefix ''facebook'' or a different controller name from a > route name) > > For fun, I take an hour and experiment and rewrite the facebook > routing stuff to allow it to take options. I get it working > great...but still, there was this screwy thing with urls looking like > this in canvas: > > http://apps.facebook.com/appname/facebook/... > > and therefore hitting the rails routing as: > > http://mydomain.com/facebook/facebook/.... > > Ok, so then I try a manual route, just to try and get it working: > > map.facebook_accounts ''/facebook/:action/:id'', :controller => > ''facebook_accounts'' > > Same deal, the first hit onto facebook is fine, but subsequent calls > are wacky. My rails app seems to be working against me. The routes I > dictate in routes.rb are not being listened to. There is magic going > on that isn''t helping me out, but making things tougher. (What makes > matters worse is that people migrating from rFacebook are used to > being more or less in control of their routes and probably have a > different thinking cap on). > > So then I read Mike''s latest post, and I say ''ok....make a > conditional- > on-canvas route for the base route of the app.'' I''m sketched out > because I don''t really want my app being hit at the base or to define > a route at the app root - I have 90% of my non-facebook stuff running > off the root and want the facebook stuff namespaced. I try it > anyway... > > I set my facebook callback url to http://mydomain.com > > # somewhere in config/initializers > ENV[''FACEBOOKER_RELATIVE_URL_ROOT''] = '''' > > # in routes.rb > map.facebook_accounts '''', :controller => > ''facebook_accounts'', :condition => {:canvas => true} > > > Ok, that breaks everything. My normal routes no longer function, nor > do my helpers for those routes. > > After the first day of working with facebooker from my perspective, I > think the following would be helpful: > > a) rewrite map.facebook_resources to handle options so people have a > bit more flexibility (also add the GET/POST conditions to the routes) > b) make it crystal clear somewhere in the docs that by default there > is rewriting going on FOR you while in-canvas. > > I''m tempted to try out Shawns recent rewrite of the url_rewrite thing. > Is there openness to a patch being accepted? > > still not up and running, but still trying, > sudara > _______________________________________________ > Facebooker-talk mailing list > Facebooker-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/facebooker-talk-- Mike Mangino http://www.elevatedrails.com
Shawn Van Ittersum
2008-Jan-26 00:16 UTC
[Facebooker-talk] More on routing, relative_root and facebooker
On Fri, 25 Jan 2008 17:31:20 -0600, Mike Mangino wrote:> The second is that you set your facebook callback path to /facebook. > Just leave it as http://mydomain.com/ Facebooker was built so that you > can just specify your server root as the callback path. I know this > isn''t well documented. I''d love to have patches to fix the > documentation. If you include a controller name or a namespace name in > your callback path, it makes it very difficult to have multiple > environments (dev and prod) and also multiple developers.Mike, The problem with pointing the Facebook app to the root of the rails app is that we don''t want to expose all of the rails app''s other functionality through facebook. We want to sandbox the facebook app to a subset of the rails app''s functionality, which we make available through a facebook-specific controller. It is therefore a business requirement to include the controller in the callback_path, so the app will be properly sandboxed to the limited-function facebook controller. Including the controller in the callback_path does not make it any more difficult to support separate dev, test, and prod environments. We already host the entire app in three environments, so we do not need to create multiple controllers to simulate dev, test, and prod. We just need one facebook controller in each of our three rails environment instances. To connect to these different environments, we merely create three different facebook apps, each pointing to its own environment. Thus we can have our dev and test apps setup with news feed postings disabled and limited to developers only, and we can add new features to dev/test while our production app continues to serve new and existing users. I have yet to hear a good reason not to support specifying the controller on the callback_path. And there are some logic errors in facebook_url_rewriting, which I am also fixing as I add the ability to specify a longer callback_path. Also note that the changes I am implementing will not make it harder for you or anyone else to make a "facebook app basically out of the box." If you want to have all of your facebook stuff in the root of your rails app, that will still work. If you want the route from your root to a facebook controller as you seem to do now, that should still work too. The callback_path will be an optional variable with a default value to support Facebooker''s current URL rewriting behavior, so you won''t have to change a thing. And for those of us who need to sandbox the facebook to a controller with the callback_path, we will also be able to do that as well, just be adding the callback_path to our apps. Thanks, Shawn
Mike Mangino
2008-Jan-26 00:44 UTC
[Facebooker-talk] More on routing, relative_root and facebooker
Okay. I don''t necessarily agree with you, but I''ll shut up and look at your code. Please send the patch to the list to make sure I catch it. I''ve missed some on the rubyforge tracker. Mike On Jan 25, 2008, at 6:16 PM, Shawn Van Ittersum wrote:> On Fri, 25 Jan 2008 17:31:20 -0600, Mike Mangino wrote: >> The second is that you set your facebook callback path to /facebook. >> Just leave it as http://mydomain.com/ Facebooker was built so that >> you >> can just specify your server root as the callback path. I know this >> isn''t well documented. I''d love to have patches to fix the >> documentation. If you include a controller name or a namespace name >> in >> your callback path, it makes it very difficult to have multiple >> environments (dev and prod) and also multiple developers. > > Mike, > > The problem with pointing the Facebook app to the root of the rails > app is that we don''t want to expose all of the rails app''s other > functionality through facebook. We want to sandbox the facebook app > to a subset of the rails app''s functionality, which we make > available through a facebook-specific controller. It is therefore a > business requirement to include the controller in the callback_path, > so the app will be properly sandboxed to the limited-function > facebook controller. > > Including the controller in the callback_path does not make it any > more difficult to support separate dev, test, and prod > environments. We already host the entire app in three environments, > so we do not need to create multiple controllers to simulate dev, > test, and prod. We just need one facebook controller in each of our > three rails environment instances. To connect to these different > environments, we merely create three different facebook apps, each > pointing to its own environment. Thus we can have our dev and test > apps setup with news feed postings disabled and limited to > developers only, and we can add new features to dev/test while our > production app continues to serve new and existing users. > > I have yet to hear a good reason not to support specifying the > controller on the callback_path. And there are some logic errors in > facebook_url_rewriting, which I am also fixing as I add the ability > to specify a longer callback_path. > > Also note that the changes I am implementing will not make it harder > for you or anyone else to make a "facebook app basically out of the > box." If you want to have all of your facebook stuff in the root of > your rails app, that will still work. If you want the route from > your root to a facebook controller as you seem to do now, that > should still work too. The callback_path will be an optional > variable with a default value to support Facebooker''s current URL > rewriting behavior, so you won''t have to change a thing. And for > those of us who need to sandbox the facebook to a controller with > the callback_path, we will also be able to do that as well, just be > adding the callback_path to our apps. > > Thanks, > Shawn-- Mike Mangino http://www.elevatedrails.com