ironsand
ironsand

Reputation: 15151

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

I can mark a post by using unread gem.

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?

Upvotes: 0

Views: 1179

Answers (2)

randomcontrol
randomcontrol

Reputation: 2282

My working approach is:

post.read_mark(current_user).destroy!

Upvotes: 0

jkeuhlen
jkeuhlen

Reputation: 4517

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)
  end

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.

Upvotes: 1

Related Questions