title: How would I get all posts that a tag belongs to? Rails
body: <p>So the way I did things for these model set ups is a bit different then what you might actually do. How ever I did things like this:</p>
  <h1>Post Model</h1>
  <pre><code>class Post &lt; ActiveRecord::Base
    belongs_to :blog
    belongs_to :user
  
    has_and_belongs_to_many :tags, join_table: 'tags_posts', :dependent =&gt; :destroy
    has_and_belongs_to_many :categories, join_table: 'categories_posts', :dependent =&gt; :destroy
    has_many :comments, :dependent =&gt; :destroy
  
    validates :title, presence: true
  
    def has_tag?(tag_name)
     tags.where(name: tag_name).any?
    end
  
    def tag_names
      tags.pluck(:name)
    end
  
    def tag_names=(names)
      self.tags = names.map{ |name| Tag.where(name: name).first }
    end
  
    def tag_name=(tag_name)
      single_tag = [tag_name]
      self.tag_names = single_tag
    end
  
    def has_category?(category_name)
     categories.where(name: category_name).any?
    end
  
    def category_names
      categories.pluck(:name)
    end
  
    def category_names=(names)
      self.categories = names.map{ |name| Category.where(name: name).first }
    end
  
    def category_name=(category_name)
        single_category_name = [category_name]
        self.category_names = single_category_name
    end
  
    def user=(id)
      user = User.find_by(id: id)
      self.user_id = user.id if user
    end
  
  end
  </code></pre>
  <p>The above allows us to assign tags and categories and a post to a user (the last part is being refactored out as we speak). You can also get all tags and categories for a post and see if that post has a particular category.</p>
  <p>Now what I want to do, in the tags model (for now) is get all the posts that a tag belongs to. But I am not sure how to do that ...</p>
  <p>this is my tags model:</p>
  <h1>Tags Model</h1>
  <pre><code>class Tag &lt; ActiveRecord::Base
    belongs_to :blog
    validates :name, presence: true, uniqueness: true
  end
  </code></pre>
  <p><strong>How do I accomplish what I want?</strong></p>