Rails.version
=> "5.2.4.1"
ActsAsTaggableOn::VERSION
=> "6.5.0"
model
class Model < ApplicationRecord
acts_as_taggable
end
To eliminate N + 1, use includes (: tags)
and then call [tags] 1 instead of [tag_list].
#Calling tags
Model.includes(:tags).each{|m| m.tags }
# acts_as_When using taggable skills etc.
Model.includes(:tags).each{|m| m.skills }
# tag_If you call list, N+1 will inevitably occur
# Model.includes(:tags).each{|m| m.tag_list }
# tag_To be the same as list...
Model.includes(:tags).each{|m| m.tags.map(&:name) }
Recommended Posts