views:

764

answers:

2

i have an existing rails application to which i am adding a new controller to handle requests from a small facebook app (using the facebooker plugin) i am building.

in the facebook app's config i set the canvas callback url to http://my.host.ip/fb/

in a pure facebook application the url would leave off the /fb/ and the user would be directed to the app's home page. but since this is an existing application, i cannot do that.

now in my routes.rb i have:

map.connect '/fb/like/:id', :controller => 'facebook_app', :action => "like" map.connect '/fb/:category', :controller => 'facebook_app', :action => "index", :category => "default"

so when the user visits http://apps.facebook.com/my_app_name/ facebook makes a call to http://my.host.ip/fb/

and that renders fine.

on that page i have links to the "like" action:

<%= link_to "like", :controller => "fb", :action => "like", :id => id %>

only problem is these get rendered as:

http://apps.facebook.com/my_app_name/fb/like/12345

when what i want is:

http://apps.facebook.com/my_app_name/like/12345

see how the /fb/ is causing me grief?

is there a way around this? either some way in the routes definition to say that the /fb/ was only for incoming URLs? or some way in the url generator to omit the /fb/?

i found one workaround... if i add this route above the existing "like" route:

map.connect '/like/:id', :controller => 'facebook_app', :action => "like"

then that first route is what's used by the link_to url generator and the correct URL gets generated:

http://apps.facebook.com/my_app_name/like/12345

which when clicked causes facebook to make this request to my app:

http://my.host.ip/fb/like/12345

which is matched by the original "like" route.

i'd rather not have to do this for every action in my facebook controller though.

A: 

You could maybe try to set your callback_url to just http://my.host.ip/. In that action, you can then detect if the request comes from Facebook with request_comes_from_facebook? method and redirect it to your facebook controller if it`s the case.

Then your subsequent links would work.

Pierre Olivier Martel
+1  A: 

Mike Mangino responded to this here: http://groups.google.com/group/facebooker/browse_thread/thread/bd37517738282a9a/91dc95ef3b1889ac?lnk=gst&amp;q=route#91dc95ef3b1889ac

Udi
why isn't that working for me then? It looks like it's ignoring the :conditions => {:canvas => true} option so that it takes over / from map.home...lame
simianarmy