Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sungwoncho/acts_as_liked
Add like feature to any Active Record models.
https://github.com/sungwoncho/acts_as_liked
Last synced: about 2 months ago
JSON representation
Add like feature to any Active Record models.
- Host: GitHub
- URL: https://github.com/sungwoncho/acts_as_liked
- Owner: sungwoncho
- License: mit
- Created: 2014-11-28T08:50:07.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2014-12-11T06:58:26.000Z (about 10 years ago)
- Last Synced: 2024-11-01T18:51:46.025Z (2 months ago)
- Language: Ruby
- Homepage:
- Size: 340 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# ActsAsLiked [![Build Status](https://travis-ci.org/sungwoncho/acts_as_liked.svg?branch=master)](https://travis-ci.org/sungwoncho/acts_as_liked) [![Coverage Status](https://coveralls.io/repos/sungwoncho/acts_as_liked/badge.png?branch=master)](https://coveralls.io/r/sungwoncho/acts_as_liked?branch=master)
Add like feature to any Active Record models through polymorphic association. Designate any models to act as a *Liker* or *Likeable*.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'acts_as_liked'
```And then execute:
$ bundle
Run generator:
$ rails generate acts_as_liked
And don't forget to migrate your database
$ rake db:migrate
## Usage
### Likeable models
Add `acts_as_likeable` to any models, and its instances can be liked by other models.
```ruby
class Post < ActiveRecord::Base
acts_as_likeable
end
```### Liker models
Add `acts_as_liker` to any models, and it can like instances of other models.
```ruby
class User < ActiveRecord::Base
acts_as_liker
end
```It is not necessary to use both `acts_as_liker` and `acts_as_likeable`. You can simply drop in one of them into your model and you will be good to go.
### API
Following APIs will be provided to *Likeable* and *Liker*.
*Likeable*
```ruby
# Count the number of likes of @post
@post.like_count# Check if @post is liked by @user
@post.liked_by?(@user)# Create a new Like record for @user, and @post
@post.liked_by(@user)# Destroy the Like record
@post.unliked_by(@user)
```*Liker*
```ruby
# Create a new Like record for @user, and @post
@user.like(@post)# Destroy the Like record
@user.unlike(@post)# Check if @user has liked @post
@user.liked?(@post)
```## Contributing
Issues and pull reqeusts are welcomed.