Code Monkey home page Code Monkey logo

has_many_friends's Introduction

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.


Setup
=====
To use this plugin, you will first need to install it. This can be done quite simply
with the following command.

   script/plugin install http://svn.dnite.org/has_many_friends

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.

   class User < ActiveRecord::Base
     has_many_friends
     # the rest of your user model ...
     # ...
   end


Usage
=====
After the plugin is installed. All of these super cool methods will be attached to 
any user.

These methods are the actual associations. They return what you'd expect.
   user.friends_for_me
   user.friends_by_me
   user.pending_friends_for_me
   user.pending_friends_by_me

Again, these will return what you would expect them to return.
   user.friends
   user.pending_friends
   user.pending_or_accepted_friends

## The following 3 methods were changed as of revision 8. They have been listed here
## as these methods, but for some reason, i never changed their names in the actual
## plugin file. If your using a pre-8 version and things broke for you, use the new
## method names in your application. Sorry for the inconvenience.
Returns true if user is friends with friend.
   user.is_friends_with? friend
   user.is_pending_friends_with? friend
   user.is_friends_or_pending_with? friend

Creates, deletes or updates friendship requests.
   user.request_friendship_with friend
   user.delete_friendship_with friend
   user.accept_friendship_with friend

Bypass the request and just make a friend.
   user.become_friends_with! friend

Returns the friendship object (good for looking up extra attributes about
the friendship, like when it was accepted and such.
   user.friendship friend

Copyright (c) 2007 Steve Ehrenberg, released under the MIT license

has_many_friends's People

Contributors

swemoney avatar

Watchers

Thor  avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.