This is probably easy but I’m totally lost.
Basically I need to let a user send a message to multiple users but keep conversations ‘filtered’ in a way that recipients can only see the messages from the originator and the ones they own.
def create
recipients = User.where(id: params['recipients'])
recipients.each do |recipient|
conversation = current_user.send_message(recipient, params[:message][:body], params[:message][:subject]).conversation
end
flash[:success] = "Message has been sent!"
redirect_to conversations_path
end
I need some way a user can send the same message to multiple users but keep the conversations separated.
I guess this may sound weird and it misses the all idea of conversations.
I was thinking I could make this the default behavior and add a checkbox on new message view to set the message to be a private conversation (splitting it) or grouped.
Does it make sense? Is it possible or am I thinking it the wrong way and should build something from scratch?
Thanks so much for taking the time to write this. It really helped in getting mailboxer setup. I couldn’t find any solid docs on implementing the Message#create method for multiple models, since the recipients array is just id’s (might be possible/easier if looking up by unique usernames). I ended up doing it this way for anyone that needs some direction.
In the recipients_options helper, I updated the value to include the class (User, Duck, Cylon, etc.):
If you were following my tutorial, this should work right away. Doesn’t it work in the demo app on Heroku? If does, but you are experiencing errors with the same code, that’s most likely a bug and should be reported to the dev team I believe.
Hi, I’ve tried using @chosen_recipients to fill the recipient value with user_id. It is able to grab the id i.e. “new?=2” but it does not populate recipient value when the message is being created and sent. any thoughts?