Go to file
ZengTao 3cdc39edce [UPDATE] where(id: ids)返回 relations对象 find(ids)返回 Array对象 2017-06-29 14:43:49 +08:00
bin init followable gem 2016-06-20 12:12:09 +08:00
lib [UPDATE] where(id: ids)返回 relations对象 find(ids)返回 Array对象 2017-06-29 14:43:49 +08:00
spec init followable gem 2016-06-20 12:12:09 +08:00
.gitignore init followable gem 2016-06-20 12:12:09 +08:00
.rspec init followable gem 2016-06-20 12:12:09 +08:00
.travis.yml init followable gem 2016-06-20 12:12:09 +08:00
CODE_OF_CONDUCT.md init followable gem 2016-06-20 12:12:09 +08:00
Gemfile init followable gem 2016-06-20 12:12:09 +08:00
LICENSE.txt init followable gem 2016-06-20 12:12:09 +08:00
README.md update readme 2017-01-18 14:45:30 +08:00
Rakefile init followable gem 2016-06-20 12:12:09 +08:00
acts_as_followable.gemspec add generator 2016-06-20 15:57:31 +08:00

README.md

ActsAsFollowable

这就是一个给国人用的 关注(点赞)有关的 Gem 目前仅仅只想支持Rails5

Installation

Add this line to your application's Gemfile:

gem 'acts_as_followable', git: 'git://github.com/w-zengtao/acts_as_followable.git'

And then execute:

$ bundle

Usage

最开始你需要:

rails g acts_as_followable
rails db:migrate

然后有两个类方法可以放在需要使用的类中:

acts_as_followable  #被关注
acts_as_follower    #关注者

class Article < ApplicationRecord
  acts_as_followable
end

class User < ApplicationRecord
  acts_as_follower
end

acts_as_followable

acts_as_followable

#找出某个模型关注我的所有的对象
Article.followers_by_type('User')

acts_as_follower

acts_as_follower

# 关注某个模型的某个对象
User.first.follow(Article.first)
# 万恶的取关
User.first.unfollow(Article.first)
# 查看是否关注某个对象
User.first.follow?(Article.first)
# 查看关注模型的所有对象 
User.first.followings('Article')

以上是目前实现的功能 还有黑名单等功能待实现

License

The gem is available as open source under the terms of the MIT License.