ruby on rails - How to create a Report Class for handling user abuse, fake profile, inappropriate photos? -


i want users able report other users have fake profiles, inappropriate photos, use abusive language etc. thinking of creating report class capture activity. not sure associations.

for example, each user can report user once. lot of users can report given user. how can implement this?

you can have report model polymorphic association others

class report < activerecord::base   belongs_to :reportable, polymorphic: true   belongs_to :user end  class photo  < activerecord::base   has_many :reports, as: :reportable end  class profile  < activerecord::base   has_many :reports, as: :reportable end  class user < activerecord::base   has_many :reports                 # allow user report others   has_many :reports, as: :reportable # allow user reported end 

your reports table have fields like:

id, title, content, user_id(who reports this), reportable_type, reportable_id 

to make sure user can report 1 instance of 1 type once(say user can report user's profile once), add validation in report model

validates_uniqueness_of :user_id, scope: [:reportable_type, :reportable_id] 

these settings should able satisfy requirements.

for validation part, dylan markow @ answer


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -