Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Eager loading with Gem Mailboxer

Gems / Libraries • Asked by Thomas M

Hello everyone,

I have a User model which act_as_messageable using the Mailboxer gem.
In my users#index view, I would like to add a link for each user to the first user conversation

Right now, I have my link which looks like this :
<%= link_to conversation_path(user.mailbox.conversations.first) do %>Button to conv<% end %>

It works but, since I didn't include the conversations when I requested the users, I see a lot of n+1 queries.
How can I load the conversations at the same time than the users ?

I already tried User.all.includes(mailbox: :conversations) with no luck

Thank you in advance for your help !
Kind Regards

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,575+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.