belongs_to association loaded individually even after eager loading

五迷三道 提交于 2019-12-05 22:12:37

If you're only displaying the user's name, how about grabbing it in the query along with an inner join?

Query:

@pictures = Picture.select("pictures.*, users.name as user_name").joins(:user).all

View:

- @pictures.each do |picture| 
  %tr
    %td= picture.name
    %td= picture.user_name
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!