简体   繁体   English

你能推荐一个使用 Rails 3 生成 facebook 风格消息收件箱的插件或 gem 吗?

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

I want a way for users to send and receive messages and to see them in an inbox similar to how it is done in Facebook: it shows the subject and knows whether the particular message was received or sent, and then clicking shows the entire thread.我想要一种让用户发送和接收消息并在收件箱中查看它们的方法,类似于在 Facebook 中的操作方式:它显示主题并知道是否接收或发送了特定消息,然后单击显示整个线程。

I have been trying to use a single Message record with a UserMessage -- one for the sender, the other for the recipient -- but not exactly sure how to, for example, show all the messages for a User whether a recipient or sender.我一直在尝试将单个消息记录与 UserMessage 一起使用——一个用于发件人,另一个用于收件人——但不完全确定如何显示用户的所有消息,例如,无论是收件人还是发件人。

Ideally, someone has already done this in a plugin or gem I can repurpose.理想情况下,有人已经在我可以重新利用的插件或 gem 中做到了这一点。

has_mailbox gem has_mailbox宝石

is there to send messages between users, I'm testing it on my sample porject right now:) and dont forget to add will_paginate gem in gem file because for now ha_mailbox gem shows error incase will_paginate is not in gem file.是否可以在用户之间发送消息,我现在正在我的示例项目上对其进行测试:) 并且不要忘记在 gem 文件中添加 will_paginate gem,因为现在 ha_mailbox gem 显示错误,以防 will_paginate 不在 gem 文件中。 I think it is dependent on it我认为这取决于它

This is not a very difficult task for you to handle.这对你来说不是一个很难处理的任务。 We want to be able to send messages between users.我们希望能够在用户之间发送消息。 Let's say we have a User model that looks something like (for the sake of simplicity)假设我们有一个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

and a Message model that looks like (also for the sake of simplicity)和一条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

and a Msgcontent model that looks like和一个看起来像的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

Now that you have those models set up, in your controller you might have something like.现在您已经设置了这些模型,在您的 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

Where params[:user_id] is the current user signed in and params[:message_id] is the message that you want to show in detail.其中params[:user_id]是当前登录用户, params[:message_id]是您要详细显示的消息。 You can also combine the 2 variables into one variable, but you might want to separate it, it's up to you.您也可以将 2 个变量合并为一个变量,但您可能需要将其分开,这取决于您。 This way, in your view you can appropriately display all the messages that have been sent and received by a user.这样,在您的视图中,您可以适当地显示用户已发送和接收的所有消息。 I'm not going to write a whole view worth of code, but basically there's the show_all_messages that gets all messages that the user is a part of, and the show_message_detail will get the whole thread of the message.我不会编写完整的代码视图,但基本上有show_all_messages获取用户所属的所有消息,而show_message_detail将获取消息的整个线程。 I will leave this part to you:)我会把这部分留给你:)

If you want to be able to tell whether a user has seen the message or not, you can add 2 fields to your Message model, which would then result into如果您希望能够判断用户是否已看到该消息,您可以在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

Now you will know the last date that the sender or recipient has looked at your message.现在您将知道发件人或收件人查看您的邮件的最后日期。 In your show_all_messages you would need to update your Message model to reflect the two columns you've added to your table.在您的show_all_messages中,您需要更新您的Message model 以反映您添加到表中的两列。 Then to able to get the messages after the _lastviewed you need to use conditions in your code, which can be found here然后为了能够在_lastviewed之后获取消息,您需要在代码中使用条件,可以在此处找到

If you really want to find a gem, you can probably can with some diligent googling, however there are some very basic Rails (and database) concepts here that is essential for you to understand if you want to rely on your own knowledge for future development.如果你真的想找到一个 gem,你可能可以通过一些勤奋的谷歌搜索,但是这里有一些非常基本的 Rails(和数据库)概念,如果你想依靠自己的知识进行未来的开发,这些概念对于你来说是必不可少的.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 你能为Ruby on Rails推荐好的数据网格类/ gem吗? - Can you recommend good data grid class/gem for Ruby on Rails? Rails 3 facebook插件/ gem? - Rails 3 facebook plugin/gem? 无法使用Rails邮件gem在GMail收件箱上设置:DELETE标志 - Can not set :DELETE flag on GMail Inbox using rails mail gem Rails-提及gem / plugin以实现收件箱功能 - Rails - Mention the gem/plugin to implement inbox feature 实现facebook风格的消息传递系统,其中用户可以位于另一个模型的两个不同列中 - Implementing a facebook-style messaging system, where a user can be in either of two different columns of another model 您建议使用哪种Ruby on Rails插件/ gem在自定义博客中实现广泛使用的博客发布API(Atom,MetaWeblog等) - What Ruby on Rails plugin/gem would you recommend to implement widely-used blog publishing API (Atom, MetaWeblog, etc) in a custom blog Ruby on Rails:您是否建议使用Observers? - Ruby on Rails: Do you recommend using Observers? 在带有Rails的页面上显示下一组结果,例如Facebook风格的“旧帖子”链接,以查看下一组新闻 - Show next set of results in page with Rails, like Facebook-style “older posts” link to see next set of news items 您可以推荐浏览器中的Ruby / Rails 3D渲染器吗? - Can you recommend an in-browser Ruby/Rails 3D renderer? 插件/ Gem在Rails 2.3.x中获得Rails 3风格的UJS? - Plugin/Gem to get Rails 3 style UJS in Rails 2.3.x?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM