1 — What do I have:
- User model and Social Networks Model
- A user can have many social networks and a social network belongs to a user
- I store the token, uid and name of the social network (and the user id) in the social networks table.
2 — What do I want:
I want a logged in user to be able to go to ‘/socialnetworks’ and get a list of all the social networks that he has linked (those that are in the social network table with a token different that nil) and all those social networks that he has not linked but the app supports. For each active social network, the user will be able to unlink it if it’s linked and link it if it’s unliked.
3 — How I have thought of doing this:
I’ve been thinking on doing this in a RESTful way but I believe it confuses me the fact that I don’t want to show the same information for each social network . For example, for Facebook I might want to show the picture profile and first name, and for Twitter I might want to show the number of followers and the number of people the user is following. In any case, what I have thought on doing:
In the index action I will have callers to different builders for each social network. So, for example I could have the following:
def index
@facebook_object = SocialNetworks.get_facebook_object
@twitter_object = SocialNetworks.get_twitter_object
end
In the index template I have thought on doing something like:
render facebook_template
render twitter_template
Which would render the different partials for the given objects or if they don’t exist they would show the “link to the X social network” button.
So my question is: How could I improve this design to make it more RESTful and at the same time strong to future changes or addition of new social networks?
You could use nested resources if you want to be RESTFul.
You can also keep one template for rendering your social network object, and keep the logic of rendering a dedicated or a generic template in it.