How to model a feedback system

1

I'm developing an application in Rails. I would like to know how to model the comments part. There is a table for the calls (Helpdesk system), and it is related to the history table, which is the comments. My question is, how can I find out who made a comment, because the call table is related to the table of call_funcionarios, and the table of users, and I need to filter who commented.

    
asked by anonymous 02.04.2015 / 21:40

1 answer

1

Your history table also needs to have the id of the commenting user. After that, add belongs_to :usuario (for example).

To relate the chamada table to the usuario table, using the chamada_funcionarios table to relate them, for example, you need to add this relation in the Chamada ( has_one :usuario, through: :chamada_funcionarios ) model.

When you make these relations, you can consult the author of the call by the model Chamada and the author of the comments by the model Historico .

For example:

chamada = Chamada.first
comentarios = chamada.historicos
puts "Chamada #{chamada.id}:"
puts "Autor: #{chamada.usuario.nome}"

comentarios.each do |comentario|
  puts "Comentário #{comentario.id}"
  puts "Autor do comentário: #{comentario.usuario.nome}"
end
    
22.01.2016 / 14:47