Sha256: 996609b73353b642a6f92eca07227c5e8850e4ffe33b0d210b14d2111df131b7
Contents?: true
Size: 672 Bytes
Versions: 3
Compression:
Stored size: 672 Bytes
Contents
module PersonalBlog class Post < ActiveRecord::Base has_many :comments, dependent: :destroy has_many :taggings, dependent: :destroy has_many :tags, through: :taggings before_create :set_published_at validates :title, presence: true validates :body, presence: true def all_tags=(names) self.tags = names.split(",").map do |name| Tag.where(name: name.strip).first_or_create! end end def all_tags self.tags.map(&:name).join(", ") end def self.tagged_with(name) Tag.find_by_name!(name).posts end private def set_published_at self.published_at = Time.now end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
personal_blog-0.0.3 | app/models/personal_blog/post.rb |
personal_blog-0.0.2 | app/models/personal_blog/post.rb |
personal_blog-0.0.1 | app/models/personal_blog/post.rb |