Sha256: 45bcb93ed3fa7fa9e8a6fddbf0d751a88264aefac0e3034ddafee70aa98742bc
Contents?: true
Size: 835 Bytes
Versions: 1
Compression:
Stored size: 835 Bytes
Contents
module Storytime class Post < ActiveRecord::Base include Storytime::Concerns::HasVersions belongs_to :user has_many :taggings, dependent: :destroy has_many :tags, through: :taggings validates_presence_of :title, :excerpt, :draft_content validates :title, length: { in: 1..200 } validates :excerpt, length: { in: 1..200 } def self.tagged_with(name) Tag.find_by_name!(name).posts end def self.tag_counts Tag.select("storytime_tags.*, count(storytime_taggings.tag_id) as count").joins(:taggings).group("storytime_taggings.tag_id") end def tag_list tags.map(&:name).join(", ") end def tag_list=(names) self.taggings.destroy_all self.tags = names.split(",").map do |n| Tag.where(name: n.strip).first_or_create! end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
storytime-0.0.1 | app/models/storytime/post.rb |