Using the ActsAsTaggableOn gem, taggable object is Template. Plus these associations:
class Template
acts_as_taggable
has_many :template_designs
end
class Pins
belongs_to :template
belongs_to :tag
end
class Tags
has_many :taggings
end
Goal: a collection of templates ready to be paginated where the user selects a tag, we find all templates matching that tag, and sort them by whether the same tag and template exist in pins, with trues on top.
EDIT - Simplifying and paraphrasing.
Given that a Template is tagged with Tags, and those Tags may or may not have a Pin, I need to select all Templates with X tag, and sort them whether that Tag has a Pin (boolean sort, trues on top).