Skip to content

culturecode/acts_as_readable

 
 

Repository files navigation

ActsAsReadable allows you to create a generic relationship of items which can be marked as ‘read’ by users. This is useful for forums or any other kind of situation where you might need to know whether or not a user has seen a particular model.

TODO…

class Post < ActiveRecord::Base acts_as_readable end

bob = User.find_by_name(“bob”)

bob.readings # => []

Post.unread_by(bob) # => [<Post 1>,<Post 2>,<Post 3>…] Post.read_by(bob) # => []

Post.find(1).read_by?(bob) # => false Post.find(1).read_by!(bob) # => <Reading 1> Post.find(1).read_by?(bob) # => true Post.find(1).readers # => [<User bob>]

Post.unread_by(bob) # => [<Post 2>,<Post 3>…] Post.read_by(bob) # => [<Post 1>]

bob.readings # => [<Reading 1>]

Version 2.4.0 now supports reading and querying against STI subclasses, even when the read and queried subclass don’t match. This requires you to migrate the readings.readable_type column data to the base class name of the stored class name, as in versions prior to 2.4.0 the column stored the class name of whatever instance was being read, event STI subclasses.

There are multiple gemfiles available for testing against different Rails versions. Set BUNDLE_GEMFILE to target them, e.g.

bundle install
BUNDLE_GEMFILE=gemfiles/rails7.gemfile bundle exec rspec

Copyright © 2024 Culture Code Software Consulting. Released under the MIT license

About

A simple plugin that allows a user to mark anything as 'read.' Common usage would include forum posts, news items, etc.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Ruby 100.0%