Ask A Question

Notifications

You’re not receiving notifications from this thread.

Eager loading with Gem Mailboxer

Thomas M asked in Gems / Libraries

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
Thomas

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 85,376+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.