更新一下写法 和 相关的文档

This commit is contained in:
w-zengtao 2018-03-15 16:19:55 +08:00
parent 3cdc39edce
commit fff7ad7c76
3 changed files with 7 additions and 8 deletions

View File

@ -41,7 +41,7 @@ acts_as_followable
acts_as_followable
#找出某个模型关注我的所有的对象
Article.followers_by_type('User')
Article.followers_by_type(User)
```
acts_as_follower
@ -54,8 +54,8 @@ User.first.follow(Article.first)
User.first.unfollow(Article.first)
# 查看是否关注某个对象
User.first.follow?(Article.first)
# 查看关注模型的所有对象
User.first.followings('Article')
# 查看关注模型的所有对象
User.first.followings(Article)
```
以上是目前实现的功能 还有黑名单等功能待实现
## License

View File

@ -27,8 +27,8 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.12"
spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"
spec.add_development_dependency "rails", "~> 4.0"
spec.add_development_dependency "rails", "~> 5.0"
end

View File

@ -22,13 +22,12 @@ module ActsAsFollowable
end
def followers_by_type(follower_type, options = {})
klass = follower_type.constantize
ids = Follow.
where('followable_id' => self.id,
'followable_type' => class_name(self),
'follower_type' => follower_type
).pluck('follower_id')
return klass.find(ids)
return follower_type.find(ids)
end
end
end
@ -64,7 +63,7 @@ module ActsAsFollowable
end
def followings(followable_type)
return followable_type.constantize.where(id: self.follows.where(followable_type: followable_type).pluck(:followable_id))
return followable_type.where(id: self.follows.where(followable_type: followable_type).pluck(:followable_id))
end
private