Messaging with Rails and Mailboxer

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 https://github.com/bodrovis/SitePoint-Mailboxer/blob/master/app/controllers/messages_controller.rb#L8 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!

I’d wish to explain what went wrong but without seeing any code that would be hard. Could you share some relevant pieces of code?

Great perfect and simple. I update my version with this and workout great.

Glad to be helpful!

Can you do a how to do in app notification from mailboxer(Facebook like). Love to see how to use that part of mailboxer.

That depends on what you mean. By all means I’d love to research this topic, moreover, I already has something like this in pipeline (though it will take some time, because currently I am working on authorization and file uploads). Are we talking about notifications in mailboxer (like someone has written you a message)?

Yes, like a notification icon on the header of the app so when you login you can view the notification.

Thank you for explaining the process and sorry for not replying earlier!

I know how to redirect a buyer to the new message page after an order has been charged.

Not sure on how to set the seller’s id in the hidden field or how to check the attributes in the messages controller

Well, once again withot seeing the code I can’t give some exact advices, but if you already have those ids, then you just utilize hidden_field_tag (http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-hidden_field_tag) to save those values, and then in controller just access params hash and look for the key with the proper name.

hidden_field_tag 'buyer_id', id

I can’t really say more here. You can contact me via e-mail and send some code pieces so that we can discuss more

I figured it out. Thank you again for you kind help. You have been fantastic and so has this tutorial. Keep up the great work.

Great!

Hi There,

I’ve spent a couple hours knocking myself in the head. I’ve followed the tutorial as exact as I could, adding in conversations and messages. I’m right before the Add Gravatar section…

When I try to go http://localhost:3000/conversations/new, I get an error

undefined local variable or method `get_mailbox' for #<ConversationsController:0x007fb64e862548>

Is there something that’s been updated or missing from the tutorial?

Thanks!

Hrm. Could you please check your ConversationsController with the one presented here https://github.com/bodrovis/SitePoint-Mailboxer/blob/master/app/controllers/conversations_controller.rb ? If everything is the same, please open a new issue https://github.com/bodrovis/SitePoint-Mailboxer/issues and provide the full error stack trace, I’ll look into it.

Great tutorial.
Thanks for sharing it.
I just found some detail missing concerning I18n in the conversation helper.
I had to add t() to title in link_to. All the rest remaining the same.

… link_to(t(title).capitalize …

With this, I only had to add the ‘inbox’, ‘sent’, trash’ keys to my translations file and everthing worked fine.
:thumbsup:

Oh, thanks for pointing that out!