No commit activity in last 3 years
No release in over 3 years
Add favorite feature to any Active Record models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

#ActsAsFavourites Build Status Coverage Status

Add favorite fuctionalities to any Active Record models through polymorphic association.

Installation

Add this line to your application's Gemfile:

gem 'acts_as_favourites'

And then execute:

$ bundle

Run generator:

$ rails generate favorable

And don't forget to migrate your database

$ rake db:migrate

Usage

Favorable models

Add acts_as_favorable to any models, and its instances can be favorite by other models.

class Post < ActiveRecord::Base
  acts_as_favorable
end

Favoriter models

Add acts_as_favoriter to any models, and it can favorite instances of other models.

class User < ActiveRecord::Base
  acts_as_favoriter
end

It is not necessary to use both acts_as_favorable and acts_as_favoriter . You can use one to execute.

API

# Count the number of favorites of @post
@post.favorites_count

# Check if @post is favorited by @user
@post.favorite_by?(@user)

# Create a new favorite record for @user, and @post
@post.favorite_by(@user)

# Destroy the favorite record
@post.unfavorite_by(@user)

#Update
@post.update_favorite(@user)
# Create a new favorite record for @user, and @post
@user.favorite(@post)

# Destroy the favorite record
@user.unfavorite(@post)

# Check if @user favorite the @post
@user.favorite?(@post)

Contributing

Issues and pull reqeusts are welcomed.