views:

125

answers:

1

I want to create a very simple facebook application for my Rails app. At first since it is very simple, I created something in PHP, put it outside of the application space and set the callback URL to there. However, I would rather the facebook app live inside my Rails app (one reason is that so I can reuse views when necessary).

Because my facebook app will look much different and act pretty different from my Rails app, I need different views and controller actions talking to those views. My first instinct is to create a Facebook controller and somehow route all "facebook.my_domain.com" requests to the facebook controller. This will allow me to require facebook login for only requests to that controller and separate facebook app from the main app. I have read that a good method is to render different views based on the requested format but the issue is I don't want to do the same thing in the controller action if the request format is different. It seems ugly to interact with the model differently based on the request format in the controller action as opposed to mapping all requests to a Facebook controller based on the request format and interact with the model differently in the controller specific to Facebook.

Does this make sense or should I really try to not add a Facebook controller?

+1  A: 

It seems unlikely that you will be able to encapsulate all of your main application's functionality into a single controller. It seems like a very cumbersome approach.

What I would recommend is defining a method in your application_helper.rb which simply checks if the incoming request is a facebook request. Then you can use that helper method in controllers or views where you need to differentiate between the two types of requests. Given that the only differences should come in the presentation layer, you should only really need to modify controllers to render the appropriate views depending on request type along with creating the facebook views.

The only other change that you will likely need is to modify you authentication/login code. Since facebook requests don't require authentication in the same way as your regular application you will probably need to add a few conditionals for when it is a facebook request.

jkupferman