Save 36% for Black Friday! Learn more

All threads / Eager loading with Gem Mailboxer

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

Join the discussion

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

Join 39,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.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.