Skip to content

GUI Example on a real application

epicmonkey edited this page Jul 15, 2014 · 6 revisions

What mailboxer adds to you is a core for sending messages. Just by adding "acts_as_messageable" to your User (or Whatever) model you get a lot of new methods added to it. For a full API you should refer to rubydoc. This core includes several models: Message, Conversation (a wrapper of messages), Receipt (relation model between the messageable and the message), Notification (related to notification system, not messaging system), Mailbox (managing the conversations, messages and receipt of a messageable) and Messageable (modeling the new methods added to your model "acting as messageable".

Mailboxer was created as a part of SocialStream, a core to build social networks. As mailboxer is already integrated there, is a good start point to you. If you have serious problems understanding what goes now, please consider following some tutorials regarding rails 3.1, gems and engines, which will surely be helpful.

The best way to do it ruby-like and restful is to create two controllers: ConversationsController and MessagesController

To add your routes in config/routes.rb (example):

Rails.application.routes.draw do
  #...
  resources :messages
  resources :conversations
  #...
end

Your ConversationsControllers should look like this.

Your MessagesControllers should look like this.

Please, notice that there are parts of the code not related with mailboxer, as the line

before_filter :authenticate_user!

related to the authentication protocol of SocialStream.

The views are heavily dependant on your application, so this will be the part you should work the most. The example of Conversations views are here and the ones for Messages are here. Please, take into account there are also javascript dependencies (in assets and in vendor) that you should look if you want to copy it exactly this way (which I really don't recommend). The best way is to understand the views and make them your own way.