开发者

How to implement a "flag for moderator attention" feature on a Comment model in a Rails app?

开发者 https://www.devze.com 2022-12-09 17:57 出处:网络
I have a Comment model in my app but am encountering a lot of problematic postings that I have to remove manually.

I have a Comment model in my app but am encountering a lot of problematic postings that I have to remove manually.

What I want to do is add a "flag for moderator attention" feature so that users of the app have the ability to remove a commen开发者_高级运维t from view without my need to review all content in the app.

I'm thinking that after a comment has been flagged three times, I will remove it from view automatically and then when I have a chance to review these postings I will decide whether to allow them or permanently remove them from view.

What I'm having trouble with is how to implement this.

Should I have a separate table that records all items that have been flagged?

Or should I have a "flag count" field as part of the Comment table that keeps track of how many times a comment has been flagged?

A separate table would allow me to keep track of detailed information about the flagging actions - who is flagging, which IP they are flagging from, etc. This is what I'm leaning towards.

But perhaps a gem or plugin already exists that does this type of thing?


I don't know of any plugin. I like the solution you are leaning towards.

If you want to hide the comment after three flaggings have been created for it, you need to keep track of who created them, so people can flag just once.

I'd create a flag resource (which can hold any kind of flags your users can assign to particular comment), then a flagging resource which connects flags with comments and holds information about the entity which is responsible for flagging (which could be a user or a user represented by IP).

Every comment will then have many flaggings.

You can use state machine to change the status of a comment to "to_be_revised" or something similar after three flaggings have been added. State machine (aasm_state_machine or the one which is now incorporated directly into Rails) will also provide you with named_scopes for groups of comments with the same state.

After revision, you can set the state to "published" again and delete all the flaggings or to "unpublishable" and so hide it forever.


Perhaps the acts-as-flaggable plugin would work.

0

精彩评论

暂无评论...
验证码 换一张
取 消