I'm designing a web application built using Rails (+javascript, jquery, html & css and whatever else is necessary) as as a final year project of my uni degree. Part of it involves creating a conversation system for the users. I'm really struggling doing it and would appreciate any help. I'll try to explain it as best as possible:
- Using devise I've created a user account model and using ActiveRecord enums created 2 types (lets call them user, supervisor).
- An admin can change users into supervisors (this already works).
- I need to find a way of assigning a single supervisor to a user, such that a supervisor can have many users. (foreign key in database ?)
- I'm trying to create a chat/mail system where the user can only chat/mail their linked supervisor and the supervisor can have conversations with all their users.
Trying to something like this
class User < ActiveRecord::Base
enum role: [:student, :supervisor, :admin]
after_initialize :set_default_role, :if => :new_record?
def set_default_role
self.role ||= :student
end
if user.role = "supervisor"
has_many :conversations, :foreign_key => :sender_id
elsif user.role = "student"
has_one :conversations, :foreign_key => :sender_id
end
end
Aucun commentaire:
Enregistrer un commentaire