Search code examples
ruby-on-railsfacebookroutesfacebooker

proper way to setup facebook canvas url and routes in a rails app


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"

Ao 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.


Solution

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