From fff7ad7c76639b130c5b58896e161e04e9897535 Mon Sep 17 00:00:00 2001 From: w-zengtao Date: Thu, 15 Mar 2018 16:19:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=80=E4=B8=8B=E5=86=99?= =?UTF-8?q?=E6=B3=95=20=E5=92=8C=20=E7=9B=B8=E5=85=B3=E7=9A=84=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- acts_as_followable.gemspec | 4 ++-- lib/acts_as_followable/followable.rb | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index f68bcb4..5af6219 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/acts_as_followable.gemspec b/acts_as_followable.gemspec index 85d76cc..db97665 100644 --- a/acts_as_followable.gemspec +++ b/acts_as_followable.gemspec @@ -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 diff --git a/lib/acts_as_followable/followable.rb b/lib/acts_as_followable/followable.rb index 6fb4055..c524f01 100644 --- a/lib/acts_as_followable/followable.rb +++ b/lib/acts_as_followable/followable.rb @@ -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