I am using mailboxer
gem with my rails application, and i want to order my inbox messages so that when the user receives a new message, I would like to have a notification or keep track of which messages have been read and which have not and order the messages to have the unread / new messages at the top of the page.
Here is my conversations controller
class ConversationsController < ApplicationController
before_action :get_mailbox
before_action :get_conversation, except: [:index]
def index
@unread_messages = @mailbox.inbox(unread: true).count
@conversations = @mailbox.inbox({page: params[:page], per_page: 10})
end
private
def get_conversation
@conversation ||= @mailbox.conversations.find(params[:id])
end
def get_mailbox
@mailbox ||= current_user.mailbox
end
end
i tried to order the mail by:
@conversations = @mailbox.inbox({page: params[:page], per_page: 10}).joins(:receipts).select("mailboxer_conversations.*, mailboxer_receipts.*").order('mailboxer_receipts.is_read')
but it did not worked.
Please suggest a solution.