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.