Skinny controller, fat model and Facebook

As some wise man says it is good to have most logic in models not in controllers (I don’t even mention view as place for logic). Good said. But I think this is not always possible.

Lets take Facebook application in consideration. RFacebook gem (and Facebook authorization system in general) is based on HTTP session. So when You make any query to Facebook You need have access to fbsession object. As far as I know, there is no easy way to access to current HTTP session (on top which fbsession is built) from model level. As a result I don’t see possibility to build keep this schema (skinny controller, fat model) when You need retrieve any data from Facebook to make model work as needed.

In some cases You could store some data from retrieved from Facebook in own DB and then You could do operations with them without access to HTTP session. But storing most of data provided by FQL You need say in Yours application terms of service (this is how I understand Facebook’s storable attribute).

And is worth to duplicate Facebook database in order to keep up schema?

Join the Conversation

2 Comments

  1. “Skinny controller, fat model” is very good approach to get clean, maintainable and ready to reause code.
    I don’t know if I understand clearly your post (because I don’t know facebook platform and facebook libraries or tools) but I’m pretty sure that there is very simple way to follow this philosophy in your code. Even if model must have access to session object you could simply pass it as a parameter to model and work with it.

  2. I need to test it, Your idea look very interesting.

    My problem was caused by fact fbsession is object which makes calls to F8 API. So when I was trying to get access to fbsession object I got strange errors when from inside ActiveResource I was accessing ActionController. But I didn’t think about passing fbsession as parameter to model method, so I need give it try.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.