Messaging with Rails and Mailboxer

This was fantastic! Super helpful and rapid way to get mailboxer up and running with components for customization. Much appreciated!

Oh, thanks a lot!

Firstable I must say that it was difficult for me to find a way to leave a comment.

in views/messages/new.html.erb

<% page_header "Send Message to #{}" %> # @recipient here is nil

I wonder how comes that I’m the only one encountering this issue.

Thank you for the great article, you might want to add some of this stuff to their docs on github. I think they’ll appreciate the help.

I’m really sorry, this piece of code was not updated in the tutorial. There should be no @recipient of course: I will update this asap. Well noted!

P.S. :slight_smile:

It would be useful if the UI of the chat was similar to that of facebook’s. Can this be done? The options of trash can all be arranged in the pop up box.

Also the current version can be maintained so it can be used in mobiles(as pop up like facebook in a mobile won’t be responsive and clutters the minimal space.)

Well, of course this all can be done, though that would require some time. :slight_smile:

Awesome tutorial!!! I’ve been trying to integrate this with my app where after a buyer makes a purchase from a seller, they both get routed to a messenger just been them.

How can this be done?

That’s an interesting question however I do not think Mailboxer provides such functionality out of the box. Probably what you could do is store buyer’s and seller’s ids and denote that only those two can participate in some conversation, so that no one else may add messages there.

Yes, that is exactly what I’m looking for but have no idea on how to implement it. I have the buyer id and seller id stored already.

Hm, okay. I will try to research this one and write you back, as this requires me to do some testing first.

Thank you very much just for researching it. You’re definitely going above and beyond most others :slight_smile:

Once again an extremely helpful article. Thank you very much! What I have seen of mailboxer seems to assume that the sender of the message is picking the recipient out of a list of already-registered users. Does mailboxer include an option where, instead of picking from a list, the sender can just enter a name or address, and then the message is sent to that name or address? This would work like, say, gmail–as a sender, you do not need to see a dropdown of all gmail users (which would be a lot!) before sending. Rather, you just type in the address you know, the system then locates the recipient, and the message is sent, or you get an error if the address you entered is incorrect. Does mailboxer allow for something like this? If not, no worries, I will just have to make some custom methods on top of mailboxer I suppose, but just wanted to check. Thanks!

Unfortunately I stil can’t start working on this but hopefully today will have some time

Thank you!

Well, of course - this dropdown is how I implemented the whole thing however we could use another approach. Actually this dropdown was borrowed from social networks - normally you see a list of friends there :smile:

So for e-mail you’d just re-write this line to find users by e-mail, not by id and get rid of dropdown completely.

Awesome. Thanks for your quick reply. I will give it a shot.

So, here is how I think this process might look:

  1. You already have buyer’s and seller’s ids saved
  2. You redirect user to the new message page where recipient’s id (seller’s id) is already pre-populated in the hidden field. If the purchase has its own id of some kind, you may also save it in another hidden field. What would be great is to tie together the exact purchase, the buyer and the seller in some other table. Purchase id should be unique.
  3. Then in the create method you simply check those hidden attributes and if this exact buyer really made that purchase and if that purchase was processed by the provided seller. If yes - send the message.
  4. Pretty much the same can be done when replying to conversation. Once again you just check that the user who wishes to post a message there is a valid buyer or seller. Other guys won’t be able to participate in that conversation.

This is pretty basic idea but hopefully it will help you.

The tutorial goes along way, so thanks again. One thing I am struggling with is customizing the conversation and message objects a bit. Seems difficult to access the message model in order to customize it. For instance, if I want to add a few more potential fields to it, perhaps (i) a field marking the message as important or not, or (ii) a category label the user can add to a message. If it were a normal object, I could just add these items to the database table for the message (ie, t.boolean :important and/or t.string :category or something like that, and run a migration), and/or work with the message.rb file. But I do not seem to be able to access the message table or rb file. Are you aware of how to customize messages and conversations?

EDIT: I got it to work now. Nothing’s wrong with it actually I just had to reconnect to the server. So go crtl+c then rails s

I have a problem running it.
I’ve followed your tutorial up until the point before creating Avartar.
Somehow I got the error saying

undefined local variable or method `acts_as_messageable’

Have tried several ways to fix it like adding

include Mailboxer::Models::Messageable
extend Mailboxer::Models::Messageable::ActiveRecord

But nothing works. If you know how to fix this issue I’d really appreciate. Awesome tutorial btw!

Okay, great :slight_smile:

Hey but I have one more issue. I tried to integrate your code for View into my existing application, however nothing shows up even when the code exists in the view. It can compile though so no errors but I just can’t see anything at all. This time I already tried disconnecting the server also. No luck so far. Any ideas what could’ve gone wrong? Thank you so much!