Saturday, July 24, 2010

Getting Facebooker app to run in subdirectory

When I set up My Trips, my Facebook app that I used the Facebooker gem for the Facebook interface for, I intended to run it as a subdirectory of my domain name. This way I could set up multiple Facebook apps with the same domain name and IP address. However, no matter what I tried, I could not get everything to work correctly. I thought that it was issues with my web server, Nginx. However, after looking in to this more I found that it was an issue with Facebooker. You'll have to edit a Facebooker source code file. It's best to unpack the gem to your vendor directory, that way you can edit this file for the specific project.

Once you've unpacked it, edit the file vendor/gems/facebooker-1.0.xx/lib/facebooker/rails/facebook_url_rewriting.rb. Modify the relative_url_root method to the following:
class Base
class << self
alias :old_relative_url_root :relative_url_root
def relative_url_root

Where subdirectory_name is the name of the subdirectory that you want to run this app from. This is a bit of a hack, hard coding the directory that you want to run from, but it works. After you do this, you'll then have to configure your web server to run your app in a subdirectory. For Nginx with Passenger, simply add "passenger_base_url /subdirectory_name" to your nginx.conf in the server { } block. Now you can change your Canvas URL to


Fadhli Rahim said...

Hi, thanks for your post. I finally got my fb connect site up and running on a subdirectory.

However, I would like to mention that you don't have to unpack your gems. Simply just create a ruby file in your app/config/initializers/facebooker_hack.rb

and in that file just put this

Facebooker.module_eval do
def self.path_prefix

Joyce Sarpong said...


I am not technical at all, but I am facing the same problem of trying to get a Facebook app to run in a subdirectory.

The domain for my website is:

I have created separate testing and production sites. So, is the testing site and the production site is

I am testing out Facebook Connect with JomSocial on my Joomla test site and would like to use my Facebook login to login to

I have set up a Facebook app as follows:

App Domain:
Site URL:

When I login with Facebook Connect from the test site, it takes me back to and not

So my question is, how do I set up the Facebook app for GhanaOracle so that it returns to my test site when I login from the test site?

I look forward to hearing back from you.

Many thanks,