acts_as_taggable_on: how to optimize the query?

前端 未结 3 885
攒了一身酷
攒了一身酷 2021-02-08 19:14

I use acts_as_taggable_on in my current Rails project. On one overview page i am displaying an index of objects with their associated tags. I use the following code

相关标签:
3条回答
  • 2021-02-08 19:26

    Use this:

    Post.includes(:tags).all

    and then:

    post.tags.collect { |t| t.name }

    0 讨论(0)
  • 2021-02-08 19:32

    Try

    @projects = Project.includes(:categories).all

    0 讨论(0)
  • 2021-02-08 19:41

    I agree with Jan Drewniak, huge performance boosted with

    Download.includes(:tags).all
    

    and in views:

    download.tags.map {|t| link_to t, t.name}.join(', ')
    

    But still too slow.

    Any other idea?

    0 讨论(0)
提交回复
热议问题