Low commit activity in last 3 years
A long-lived project that still receives updates
Allows records to be marked as readable. Optimized for bulk, 'mark all as read' operations
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

> 5, < 8
 Project Readme

ActsAsReadable¶ ↑

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.

Installation¶ ↑

TODO…

Example¶ ↑

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>]

Upgrading from 2.3.x to 2.4.0¶ ↑

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.

Testing¶ ↑

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