i'm new rails , developing blog. want know if there tutorial on how use acts commentable threading, since instructions use github add acts_as_commentable
model.
- how should create form new comments?
- how can retrieve comments model?
- how configure routes in order show comments?
- how modify controllers make feature available?
class comment < activerecord::base acts_as_nested_set :scope => [:commentable_id, :commentable_type] #attr_accessible :commentable, :body, :user_id validates :body, :presence => true validates :user, :presence => true # note: install acts_as_votable plugin if # want user vote on quality of comments. #acts_as_votable belongs_to :commentable, :polymorphic => true # note: comments belong user belongs_to :user # helper class method allows build comment # passing commentable object, user_id, , comment text # example in readme def self.build_from(obj, user_id, comment) new \ :commentable => obj, :body => comment, :user_id => user_id end #helper method check if comment has children def has_children? self.children.any? end # helper class method lookup comments assigned # commentable types given user. scope :find_comments_by_user, lambda { |user| where(:user_id => user.id).order('created_at desc') } # helper class method comments # commentable class name , commentable id. scope :find_comments_for_commentable, lambda { |commentable_str, commentable_id| where(:commentable_type => commentable_str.to_s, :commentable_id => commentable_id).order('created_at desc') } # helper class method commentable object # given commentable class name , id def self.find_commentable(commentable_str, commentable_id) commentable_str.constantize.find(commentable_id) end end
did go through following link in github,
https://github.com/jackdempsey/acts_as_commentable
by calling command automatically create forms migration.
rails g comment
you need run migration.
which rails version using ?
Comments
Post a Comment