You can have a Report model with polymorphic association with 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 to report others
has_many :reports, as: :reportable # Allow user to be reported as well
end
Your reports
table will have fields like:
id, title, content, user_id(who reports this), reportable_type, reportable_id
To make sure an user can only report one instance of one type once(Say an user can only report another user's profile once), just add this validation in Report model
validates_uniqueness_of :user_id, scope: [:reportable_type, :reportable_id]
These settings should be able to satisfy the requirements.
For validation part, thanks to Dylan Markow at this answer