mardi 14 mai 2019

How can I set the user_type in the mailboxer_notifications table?

My problem is that when users reply to each other, it's hard examine the database via SQL and differentiate between user types (so admin, and individual users). The default is just "User", as a string.

When examining the mailboxer code, I know it calls the "reply" method in the Conversations controller. This is the relevant part of the code:

def reply
  current_user.reply_to_conversation(conversation, message_params[:body])
  flash[:notice] = "Message was sent."
  redirect_to conversation_path(conversation)
end

From this, I wanted to do something like:

conversation.messages.sender_type = params[:custom].present? ? params[:custom] : "Admin"

But this does not work, as it says "unknown sender type method". I listed it that way because, based on the mail boxer gem code, messages belongs_to conversation, and the messages model is linked to the table and column value I want to change.

This is the relevant code: https://github.com/mailboxer/mailboxer/blob/03543e8a06dea8c9bfb52963da8abbf1157d5d21/app/models/mailboxer/message.rb

Based on this, what should I modify to have it so when I reply to a user, the reply action is called, and then conversations "calls" messages which itself sets the sender_type to a value I want?

Aucun commentaire:

Enregistrer un commentaire