Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
A

acts_as_follower

> 编程语言
Open source

A Gem to add Follow functionality for models

858 stars0 likes0 views
WebsiteGitHub

About

A Gem to add Follow functionality for models

= acts_as_follower

acts_as_follower is a gem to allow any model to follow any other model. This is accomplished through a double polymorphic relationship on the Follow model. There is also built in support for blocking/un-blocking follow records.

Main uses would be for Users to follow other Users or for Users to follow Books, etc...

(Basically, to develop the type of follow system that GitHub has)

{}[https://travis-ci.org/tcocca/acts_as_follower]

== Installation

=== The master branch supports Rails 5

Add the gem to the gemfile: gem 'acts_as_follower', github: 'tcocca/acts_as_follower', branch: 'master'

Other instructions same as for Rails 4.

=== Rails 4.x support

The first release that support Rails 4 is 0.2.0

Add the gem to the gemfile: gem "acts_as_follower"

Run the generator: rails generate acts_as_follower

This will generate a migration file as well as a model called Follow.

=== Rails 3.x support

Rails 3 is supports in the rails_3 branch https://github.com/tcocca/acts_as_follower/tree/rails_3 The last gem release for Rails 3 support was 0.1.1, so install the gem using ~> 0.1.1

Add the gem to the gemfile: gem "acts_as_follower", '~> 0.1.1'

or install from the branch

gem "acts_as_follower", git: 'git://github.com/tcocca/acts_as_follower.git', branch: 'rails_3'

Run the generator: rails generate acts_as_follower

This will generate a migration file as well as a model called Follow.

=== Rails 2.3.x support

Rails 2.3.x is supported in the rails_2.3.x branch http://github.com/tcocca/acts_as_follower/tree/rails_2.3.x but must be installed as a plugin. The gem version does not work with rails 2.3.x.

Run the following command: script/plugin install git://github.com/tcocca/acts_as_follower.git -r rails_2.3.x

Run the generator: script/generate acts_as_follower

== Usage

=== Setup

Make your model(s) that you want to allow to be followed acts_as_followable, just add the mixin: class User false the follow is deleted. So, a user would need to try and follow the book again. I would like to hear thoughts on this, I may change this to make the follow as blocked: false instead of deleting the record.

The following methods take an optional hash parameter of ActiveRecord options (:limit, :order, etc...) followers_by_type, followers, blocks

=== Follow Model

The Follow model has a set of named_scope's. In case you want to interface directly with the Follow model you can use them. Follow.unblocked # returns all "unblocked" follow records

Follow.blocked # returns all "blocked" follow records

Follow.descending # returns all records in a descending order based on created_at datetime

This method pulls all records created after a certain date. The default is 2 weeks but it takes an optional parameter. Follow.recent Follow.recent(4.weeks.ago)

Follow.for_follower is a named_scope that is mainly there to reduce code in the modules but it could be used directly. It takes an object and will return all Follow records where the follower is the record passed in. Note that this will return all blocked and unblocked records. Follow.for_follower(user) If you don't need the blocked records just use the methods provided for this: user.all_follows

or

user.all_following

Follow.for_followable acts the same as its counterpart (for_follower). It is mainly there to reduce duplication, however it can be used directly. It takes an object that is the followed object and return all Follow records where that record is the followable. Again, this returns all blocked and unblocked records. Follow.for_followable(book) Again, if you don't need the blocked records use the method provided for this: book.followers If you need blocked records only book.blocks

== Comments/Requests

If anyone has comments or questions please let me know (tom dot cocca at gmail dot com). If you have updates or patches or want to contribute I would love to see what you have or want to add.

== Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally (acts_as_follower uses Shoulda and Factory Girl)
  • Send me a pull request. Bonus points for topic branches.

== Contributers

Thanks to everyone for their interest and time in committing to making this plugin better.

  • dougal (Douglas F Shearer) - https://github.com/dougal
  • jdg (Jonathan George) - https://github.com/jdg
  • m3talsmith (Michael Christenson II) - https://github.com/m3talsmith
  • joergbattermann (Jörg Battermann) - https://github.com/joergbattermann
  • TomK32 (Thomas R. Koll) - https://github.com/TomK32
  • drcapulet (Alex Coomans) - https://github.com/drcapulet
  • jhchabran (Jean Hadrien Chabran) - https://github.com/jhchabran
  • arthurgeek (Arthur Zapparoli) - https://github.com/arthurgeek
  • james2m (James McCarthy) - https://github.com/james2m
  • peterjm (Peter McCracken) - https://github.com/peterjm
  • merqlove (Alexander Merkulov) - https://github.com/merqlove

Please let me know if I missed you.

== Copyright

Copyright (c) 2008 - 2010 ( tom dot cocca at gmail dot com ), released under the MIT license.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言