Sha256: fd8a36f294a1b6cfc679cb49be3c1ccb55f3d7dcad2d24115eacaa4a53ae69d5
Contents?: true
Size: 606 Bytes
Versions: 5
Compression:
Stored size: 606 Bytes
Contents
class SpudPostCategory < ActiveRecord::Base spud_searchable has_and_belongs_to_many :posts, class_name: 'SpudPost', join_table: 'spud_post_categories_posts', foreign_key: 'spud_post_category_id' validates :name, :url_name, presence: true validates :name, :url_name, uniqueness: true before_validation :set_url_name after_update :touch_posts after_destroy :touch_posts scope :ordered, -> { order('name asc') } private def set_url_name self.url_name = name.parameterize end def touch_posts posts.update_all(updated_at: Time.now) if name_changed? end end
Version data entries
5 entries across 5 versions & 1 rubygems