簡體   English   中英

你能推薦一個使用 Rails 3 生成 facebook 風格消息收件箱的插件或 gem 嗎?

[英]Can you recommend a plugin or gem that generates a facebook-style message inbox using Rails 3?

我想要一種讓用戶發送和接收消息並在收件箱中查看它們的方法,類似於在 Facebook 中的操作方式:它顯示主題並知道是否接收或發送了特定消息,然后單擊顯示整個線程。

我一直在嘗試將單個消息記錄與 UserMessage 一起使用——一個用於發件人,另一個用於收件人——但不完全確定如何顯示用戶的所有消息,例如,無論是收件人還是發件人。

理想情況下,有人已經在我可以重新利用的插件或 gem 中做到了這一點。

has_mailbox寶石

是否可以在用戶之間發送消息,我現在正在我的示例項目上對其進行測試:) 並且不要忘記在 gem 文件中添加 will_paginate gem,因為現在 ha_mailbox gem 顯示錯誤,以防 will_paginate 不在 gem 文件中。 我認為這取決於它

這對你來說不是一個很難處理的任務。 我們希望能夠在用戶之間發送消息。 假設我們有一個User model 看起來像(為簡單起見)

create_table "users", :force => true do |t|
    t.string   "username",        :null => false
    t.string   "hashed_password", :null => false
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "salt",            :null => false
end

和一條Message model 看起來像(也是為了簡單起見)

create_table "messages", :force => true do |t|
    t.string   "subject",       :null => false
    t.integer  "sender_id"
    t.integer  "recipient_id"
    t.datetime "created_at"
    t.datetime "updated_at"
end

和一個看起來像的Msgcontent model

 create_table "msgcontents", :force => true do |t|
    t.string   "body",       :null => false
    t.integer  "message_id"
    t.integer  "sender_id"
    t.datetime "created_at"
    t.datetime "updated_at"
end

現在您已經設置了這些模型,在您的 controller 中您可能會有類似的東西。

def show_all_messages
    @sent_messages = Message.find_all_by_sender_id(params[:user_id])
    @received_messages = Message.find_all_by_recipient_id(params[:user_id])
end

def show_message_detail
    @thread = Msgcontent.find_all_by_message_id(params[:message_id])
end

其中params[:user_id]是當前登錄用戶, params[:message_id]是您要詳細顯示的消息。 您也可以將 2 個變量合並為一個變量,但您可能需要將其分開,這取決於您。 這樣,在您的視圖中,您可以適當地顯示用戶已發送和接收的所有消息。 我不會編寫完整的代碼視圖,但基本上有show_all_messages獲取用戶所屬的所有消息,而show_message_detail將獲取消息的整個線程。 我會把這部分留給你:)

如果您希望能夠判斷用戶是否已看到該消息,您可以在Message model 中添加 2 個字段,這將導致

create_table "messages", :force => true do |t|
    t.string   "subject",              :null => false
    t.integer  "sender_id"
    t.integer  "recipient_id"
    t.datetime "sender_lastviewed",    :null => false
    t.datetime "recipient_lastviewed", :null => false
    t.datetime "created_at"
    t.datetime "updated_at"
end

現在您將知道發件人或收件人查看您的郵件的最后日期。 在您的show_all_messages中,您需要更新您的Message model 以反映您添加到表中的兩列。 然后為了能夠在_lastviewed之后獲取消息,您需要在代碼中使用條件,可以在此處找到

如果你真的想找到一個 gem,你可能可以通過一些勤奮的谷歌搜索,但是這里有一些非常基本的 Rails(和數據庫)概念,如果你想依靠自己的知識進行未來的開發,這些概念對於你來說是必不可少的.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM