2010-11-30 106 views
0

我想在rails中設置白名單消息傳遞系統,用戶可以選擇他們想要發送評論的其他用戶。該消息可以對每個人或只有一個人可見。我將如何設置它以及消息窗體將會是什麼樣子?Rails中的消息傳遞系統

回答

2

要麼只添加連接表message_idrecipient_id

class Message 
    has_and_belongs_to_many :recipients 
end 

class Recipient 
    has_and_belongs_to_many :messages 
end 

m = Message.new 
m.recipients = list_of_recipients 
m.save 

選項正在複製每個收件人的郵件。這是一個很好的解決方案,每個收件人都可以完全控制他們的郵件收件箱(例如刪除郵件)。

class Message 
    belongs_to :recipient 

    def self.post_message(recipients, text) 
    recipients.each { |r| Message.create(:recipient => r, :text => text) } 
    end 
end 

class Recipient 
    has_many :messages 
end 
+0

第二個窗體的外觀如何?第一個你只需要創建一個accept_nested_attributes_for:收件人的權利?這是什麼樣子? – maletor 2010-12-01 20:15:08