Sha256: 3a1f6dcff8a436fd43cb85b380c9b36e773daaec9095c650004c27a857bd9f08
Contents?: true
Size: 728 Bytes
Versions: 1
Compression:
Stored size: 728 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_presence_of :name, :url_name validates_uniqueness_of :name, :url_name before_validation :set_url_name after_update :touch_posts after_destroy :touch_posts scope :ordered, ->{ order('name asc') } def self.options_for_categories() return ordered.select(:name, :url_name).collect{ |c| [c.name, c.url_name] } end private def set_url_name self.url_name = self.name.parameterize end def touch_posts if self.name_changed? self.posts.update_all(:updated_at => Time.now) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tb_blog-1.1.3 | app/models/spud_post_category.rb |