Agile Web Development

Build it. Launch it. Love it.

Friendships

This plugin is based on the work found at http://blog.hasmanythrough.com/articles/2006/04/21/self-referential-through After several instances of clients requesting a friendship system for their website, I have produced this plugin to aid in providing a generic basis for a friendship system.

Installation

1) Install the plugin from http://svn.webwideconsulting.com/svn/friendship_plugin

2) Run the generator…

3) rake migrate

4) add has_friendships to your User model

Usage

This plugin supports both very basic friendships, and confirmation of requested friendships depending on which methods you use. The User model will provide several new methods which can be easily used to manage friendships.

Basic Usage

current_user.is_friends_with? User.find(1) —> Checks if the user has the other as a confirmed friend

current_user.is_friends_with User.find(1) —> Creates a 2 way friendship without need for confirmation

current_user.is_not_friends_with User.find(1) —> Destroys both sides of any existing friendships between the 2 users.

Advanced Usage

current_user.request_friendship_of User.find(1) —> Creates an unaccepted friendship that will not show up in friendships until the other user has confirmed it

current_user.pending_friendships —> An array of friendships which have not been accepted

current_user.accept_friendship Friendship.find(1) —> Sets the friendship as confirmed, and adds the offering user as a friend of the opposite side of the friendship.

current_user.deny_friendship Friendship.find(1) —> Simply destroys the friendship in question

Other Methods

Please see the ruby/friendship_plugin.rb for methods provided directly by the self referential system. They will come in handy if you need more control over this simplistic system.

Vitals

Repository http://svn.webwideconsulting.com/plugins/friendship_plugin/
License
Tags Tag_red broken link
Rating (6 votes)
Created 19 February 2007

Comments

  • Avatar
    Andrew
    24 February 2007

    Been trying to install this plugin to play around with it however I keep getting an error. I also tried to go straight to the SVN repo through a client and it also errors however you can browse it through a browser. Would love to install it and play around as I am implementing a friendship system and want to see how others do it

  • Avatar
    8 March 2007

    You will need to check plugins out manually with svn export or co methods. There is an issue with rails ./script/plugin which does not play well with xsl styled repos, and tried to pull the stylesheet as a svn file.

  • Tobias
    17 April 2007

    I would like to use the friendship plugin in a more general way. I have two models which I would like to connect as friends, is this somehow possible? At the moment, it seems only possible to self-referentiate the models, f.e. a User-model.

Add a comment