class Tag < ActiveRecord::Base
  has_many :taggings
  has_many :episodes, through: :taggings
endThe tagged_with returns all episodes that tagged with the given term including the unpublished ones:
def self.tagged_with(name)
  Tag.find_by!(name: name).episodes
end  def self.published
    where('published_at <= ?', Time.now.utc)
  endtag = Tag.find_by!(name: 'great')
tag.episodes.merge(Episode.published)
Reference
 
 
No comments:
Post a Comment