0

I am working on implementation of the Mailboxer gem, but I am having issues with displaying messages. Here's the action where I save sent messages:

#MessagesController
  def create 
    # current_user - ID: 253
    # @user - ID: 1
    @user = User.find(params[:user_id])
    send_message = current_user.send_message(@user, params[:message][:body], params[:message][:subject]).conversation
    puts send_message.inspect
    redirect_to messages_url
  end

The output of send_message is

#<Receipt id: nil, receiver_id: 253, receiver_type: "User", notification_id: nil, is_read: true, trashed: false, deleted: false, mailbox_type: "sentbox", created_at: nil, updated_at: nil>

Shouldn't be the receiver_id #1? Also, where are these data stored, in which table?

When I display sent messages (current_user.mailbox.sentbox), I don't see there this message that I just sent out. And when I log in as the user with ID 1, I don't see there the received message neither.

What am I doing wrong?

Thank you

user984621
  • 46,344
  • 73
  • 224
  • 412

1 Answers1

1

In you create action, why don't you ensure that params[:message][:body] and params[:message][:subject] have valid values, and if not, provide a default value.

To answer your question of where the data is stored, your database will have the following tables: receipts, notifications and conversations. notifications has a conversation_id and receipts has a notification_id.

Jeff F.
  • 1,039
  • 5
  • 11