app/models/spud_post.rb in tb_blog-1.0.2 vs app/models/spud_post.rb in tb_blog-1.0.3

- old
+ new

@@ -4,12 +4,13 @@ has_and_belongs_to_many :categories, :class_name => 'SpudPostCategory', :join_table => 'spud_post_categories_posts', :foreign_key => 'spud_post_id' belongs_to :author, :class_name => 'SpudUser', :foreign_key => 'spud_user_id' - has_many :comments, :class_name => 'SpudPostComment' - has_many :visible_comments, :class_name => 'SpudPostComment',:conditions => {:spam => [nil,false]} + has_many :comments, :class_name => 'SpudPostComment', :inverse_of => :post + has_many :pending_comments, :class_name => "SpudPostComment", :conditions => {:spam => [nil, false], :approved => false} + has_many :visible_comments, :class_name => 'SpudPostComment',:conditions => {:spam => [nil,false], :approved => true} has_many :spam_comments, :class_name => "SpudPostComment", :conditions => {:spam => true} has_many :spud_permalinks,:as => :attachment has_many :spud_post_sites, :dependent => :destroy scope :publicly, where('visible = true AND published_at <= ?', Time.now.utc).order('published_at desc') @@ -27,11 +28,11 @@ def self.for_spud_site(spud_site_id) return joins(:spud_post_sites).where(:spud_post_sites => {:spud_site_id => spud_site_id}) end def self.public_posts(page, per_page) - return where('visible = ? AND published_at <= ?', true,Time.now.utc).order('published_at desc').includes(:categories).paginate(:page => page, :per_page => per_page) + return where('visible = ? AND published_at <= ?', true,Time.now.utc).order('published_at desc').paginate(:page => page, :per_page => per_page) end def self.public_blog_posts(page, per_page) return self.public_posts(page, per_page).where(:is_news => false) end @@ -134,10 +135,14 @@ def is_private? return !is_public? end + def category_names + return self.categories.collect{ |c| c.name }.join(', ') + end + # Spud site ids getter def spud_site_ids if @spud_site_ids.nil? @spud_site_ids = spud_post_sites.collect{ |site| site.spud_site_id } end @@ -151,10 +156,10 @@ else raise 'Site ids must be an Array' end end - private +private def set_url_name self.url_name = "#{self.published_at.strftime('%Y-%m-%d')}-#{self.title.parameterize}" end