Sha256: 23b1658f1439698624d8c76f77f792832c10938cb73a33b828581f7f1e2214b4
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
class Comment < ActiveRecord::Base belongs_to :commenter, :polymorphic => true, :counter_cache => true belongs_to :commentable, :polymorphic => true, :counter_cache => true validates_presence_of :body validates_length_of :body, :in => 1..250 attr_accessible :body # Helper class method to lookup all comments assigned # to all commentable types for a given commenter. def self.find_comments_by_commenter(commenter) find(:all, :conditions => ["commenter_type = ? and commenter_id = ?", commenter.class.name, commenter.id], :order => "created_at DESC" ) end # Helper class method to look up all comments for # commentable class name and commentable id. # def self.find_comments_for_commentable(commentable_str, commentable_id) def self.find_comments_for_commentable(commentable) find(:all, :conditions => ["commentable_type = ? and commentable_id = ?", commentable.class.name, commentable.id], :order => "created_at DESC" ) end # Helper class method to look up a commentable object # given the commentable class name and id # def self.find_commentable(commentable_str, commentable_id) def self.find_commentable(commentable) commentable.class.name.constantize.find(commentable.id) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jakewendt-simply_commentable-0.2.1 | app/models/comment.rb |