Go to file
来自村里的小螃蟹 503e416d4e
Update README.md
2021-12-21 10:25:18 +08:00
bin fix: extend relation 2021-05-14 17:46:45 +08:00
lib update: readme and bug 2021-06-02 18:59:35 +08:00
spec fix: remname namespace 2021-05-14 16:38:45 +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.md 2021-12-21 10:25:18 +08:00
Rakefile init followable gem 2016-06-20 12:12:09 +08:00
acts_as_able.gemspec fix 2021-05-17 18:27:28 +08:00
init.rb fix:some bug 2021-05-17 11:19:09 +08:00

README.md

ActsAsAble

这就是一个给国人用的 关注、浏览、点赞等有关的 Gem

Installation

Add this line to your application's Gemfile:

gem 'acts_as_able'

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.last.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)

浏览功能

rails g acts_as_viewable
rails db:migrate

以下方法可以放在需要使用的类中:

acts_as_viewable  #被浏览
acts_as_viewer    #浏览者


class Article < ApplicationRecord
  acts_as_viewable
end

class User < ApplicationRecord
  acts_as_viewer
end

acts_as_viewable

acts_as_viewable

#找出某个模型浏览我的所有的对象
Article.last.viewers_by_type(User)

acts_as_viewer

acts_as_viewer

# 浏览某个模型的某个对象
User.first.view(Article.first)
# 查看是否浏览某个对象
User.first.view?(Article.first)
# 查看某种类型浏览的所有对象
User.first.viewings(Article)

点赞功能

rails g acts_as_likable
rails db:migrate

以下方法可以放在需要使用的类中:

acts_as_likable  #被点赞
acts_as_liker    #点赞者


class Article < ApplicationRecord
  acts_as_likable
end

class User < ApplicationRecord
  acts_as_liker
end

acts_as_likable

acts_as_likable

#找出某个模型点赞我的所有的对象
Article.last.likers_by_type(User)

acts_as_liker

acts_as_liker

# 点赞某个模型的某个对象
User.first.like(Article.first)
# 取消某个对象的点赞
User.first.unlike(Article.first)
# 查看是否点赞某个对象
User.first.like?(Article.first)
# 查看点赞模型的所有对象
User.first.likings(Article)

踩功能

rails g acts_as_dissable
rails db:migrate

以下方法可以放在需要使用的类中:

acts_as_dissable  #被踩
acts_as_disser    #踩者


class Article < ApplicationRecord
  acts_as_dissable
end

class User < ApplicationRecord
  acts_as_disser
end

acts_as_dissable

acts_as_dissable

#找出某个模型点赞我的所有的对象
Article.last.dissers_by_type(User)

acts_as_disser

acts_as_disser

# 踩某个模型的某个对象
User.first.diss(Article.first)
# 取消某个对象的踩
User.first.undiss(Article.first)
# 查看是否踩了某个对象
User.first.diss?(Article.first)
# 查看踩模型的所有对象
User.first.dissings(Article)

评论功能

rails g acts_as_commentable
rails db:migrate

以下方法可以放在需要使用的类中:

acts_as_commentable  #被评论
acts_as_commenter    #评论者


class Article < ApplicationRecord
  acts_as_commentable
end

class User < ApplicationRecord
  acts_as_commenter
end

acts_as_commentable

acts_as_commentable

#我的所有一级评论
Article.last.root_commenters
#某个模型的一级评论
Article.last.root_commenters_by_type(User)
#找出某个模型评论我的所有的对象
Article.last.commenters_by_type(User)

acts_as_commenter

acts_as_commenter

# 评论某个模型的某个对象
User.first.comment('评论内容', Article.first, nil)
# 查看是否评论某个对象或回复某个对象
User.first.comment?(Article.first)
# 查看某种类型评论的所有对象
User.first.committings(Article)

comment

# 查看父级评论
Comment.first.parent_comment
# 查看子评论
Comment.first.children_comments

License

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