views:

37

answers:

2

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 comment 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?

A: 

I am nt sure, If this would server your purpose, but check this plugin out.

http://github.com/xing/flag%5Fshih%5Ftzu

Rishav Rastogi
I disagree with using bit fields to store values.
Bryan Locke
+1  A: 

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.

Milan Novota