ironsand ironsand - 1 year ago 60
Ruby Question

How to make status "read" to "unread" by using unread gem?

I can mark a

by using

post = Post.first
post.mark_as_read! for: current_user

But I couldn't find how to "unread" the post that is marked as "read".
How can I make it?

Answer Source

If you take a look at the issues page for the gem on github you'll see that this has been brought up there. There doesn't seem to be an official way to do this with the gem; however, user firedev over on github put up his solution.

  def mark_as_unread_except current_user
    ReadMark.where(readable_type: self.class.class_name, readable_id: id).each(&:destroy!)
    mark_as_read!(for: current_user)

This might be what you need. But take a look at the full page for commentary and ideas. As of now, there is no offical way to do this with the gem.