Manages read activities.
This gem supports to get read/unread status (including read_at), read/unread users for a specific readable, etc.
Add this line to your application's Gemfile:
gem'read_activity'And then execute:
$ bundle
Or install it yourself as:
$ gem install read_activity
Execute to generate a migration for creating ReadActivity model:
rails generate read_activity
classUser < ActiveRecord::Baseacts_as_readerendclassArticle < ActiveRecord::Baseacts_as_readableenduser=User.create!article=Article.create!user.read!(article)# or article.read_by!(user)user.read?(article)# == true# or article.read_by?(user) == trueuser.read_at(article)# or article.read_by_at(user)article.readers# == [user]# or user.read_articles == [article]# user.read_#{reader_table_name} (the plural form)article.unreaders# == []# or user.unread_articles == []# user.unread_#{readable_table_name} (the plural form)reader=article.readers.firstreader.read_at# no required params when you have fetched readers using #readersread_article=user.read_articles.firstread_article.read_by_atUser.find_who_read(article)User.find_who_unread(article)Article.find_read_by(user)Article.find_unread_by(user)- Fork it ( https://github.com/[my-github-username]/read_activity/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request