-
Notifications
You must be signed in to change notification settings - Fork 461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Working with two different models #468
Comments
Any news about this ? |
I'm not sure if you figured this out yet but since I just did it, I'll add it for others. I have two models, Client and Trainer. This is what I have in both my Client and Trainer models to satisfy Mailboxer:
The key to getting this all working smoothly (quite easy actually) is to use name spacing for the two separate models which I will assume you already do. Without launching into a full tutorial on how to setup mailboxer, I would recommend you use this one (https://www.sitepoint.com/messaging-rails-mailboxer/) to set it up for just one of the models like the Seller. Once that is done and working, you just have to copy those files to your Buyer folders. The tutorial I suggested uses a few new helpers that you will create. This was the tricky part because I had not done that for helpers before but it was pretty simple. I usually only use the application helper and had include_all_helpers set to TRUE. I had to set it to FALSE to get this to work. I needed to create separate helpers for Trainer and Client using the appropriate namespace. Then reference those helpers in the conversations_controller and the conversation_message_controller. Example of my controller:
So you are just creating two controllers (conversations and messages) for both the Buyer and Seller and using a namespace for each. Then two helpers for each and two separate set of views. You will also need to add routes for each of them in your routes files as well. So if you do the Seller first. You will want to make sure the messages are being set to the buyer and vice versa for the buyer. Also, I was already using a simple helper for current_trainer and current_client because I needed to for all of the data, etc. So instead of using current_user like in the tutorial, I used those two helpers where appropriate. I hope this is helpful. It's a bit tough without writing a full tutorial. |
Can you upload just the project components to Github and post the link? I don’t want to make a mistake and break my solution as is. I just need it for reference. |
How do you setup Mailboxer to enable cross messaging between two models? Seller and Buyer, etc.
The text was updated successfully, but these errors were encountered: