HasManyFriends – Steve Ehrenberg – http://dnite.org
has_many_friends is a plugin based off of the friendship_plugin that can be found
here (http://svn.webwideconsulting.com/svn/friendship_plugin/). This version of the
plugin adds some features I wanted as well as eliminates the need for 2 friendship
rows created in the table. The goal is to make it relatively seamless for anyone to
create a fully functional friends system for their application.
Side Note :: I developed has_many_friends on edge rails before 2.0 was released
and haven’t done any work on it since. Most of this plugin should work but if it doesn’t,
feel free to fork and submit some changes.. If I get some extra time I’ll try and test and
fix it up for Rails 3.×..
To use this plugin, you will first need to install it. This can be done quite simply
with the following command.
We’ll need to generate the model and migration for your friendship table.script/generate hmf_friendship_model Friendship rake db:migrate
If you will be running tests, you may need to prepare your test database again.rake db:test:prepare
You should be just about set! All you need to do is add the following method
to your User model.
After the plugin is installed. All of these super cool methods will be attached to
These methods are the actual associations. They return what you’d expect.
Again, these will return what you would expect them to return.
Creates, deletes or updates friendship requests.
Bypass the request and just make a friend.
Returns the friendship object (good for looking up extra attributes about
the friendship, like when it was accepted and such.
Copyright © 2008 Steve Ehrenberg, released under the MIT license
Last edited by swemoney,