2

Now I'm using a gem called 'mailboxer' for messaging system.https://github.com/ging/mailboxer
I'd like to implement 'keyword search function' for inbox, sentbox, and trash.

If I don't care about search keyword, it is fetching the result without any problem by coding like this

inbox...   @messages = current_user.mailbox.inbox.page(params[:page]).per(10)
sentbox... @messages = current_user.mailbox.sentbox.page(params[:page]).per(10)    
trash...   @messages = current_user.mailbox.trash.page(params[:page]).per(10)

But I sometimes want to filter the result with search keyword.
Assume search keyword was 'test' this time, the result should be only the records that contain 'test' within body attribute in notifications table.
How can I do this for each above such as inbox, sentbox, and trash??

I tried this but it didn't work at all :(

@messages = current_user.mailbox.inbox.search_messages(@search).page(params[:page]).per(10)
@messages = current_user.mailbox.sentbox.search_messages(@search).page(params[:page]).per(10)
@messages = current_user.mailbox.trash.search_messages(@search).page(params[:page]).per(10)
4

1 に答える 1