首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

rails 评说/回复插件 acts_as_commentable_with_threading

2013-11-15 
rails评论/回复插件 acts_as_commentable_with_threadingacts_as_commentable_with_threading ?|| ??https

rails 评论/回复插件 acts_as_commentable_with_threading

acts_as_commentable_with_threading ?|| ??https://github.com/elight/acts_as_commentable_with_threading

?

# 在被评论的model里加

class Article < ActiveRecord::Base

? acts_as_commentable

end

?

# 添加评论, 其中build_from是model里构建new的方法

@article = Article.find(params[:id])

@user_who_commented = @current_user

@comment = Comment.build_from( @article, @user_who_commented.id, "Hey guys this is my comment!" )

?

# 添加评论的回复comment: 保存了的评论, 然后用这个方法移动到parent_comment的评论下,也就是回复, 回复的评论不能是自己,回复的commentable还是被评论的对象,只是把它移动到指定评论的下面。

comment.move_to_child_of(parent_comment)

?

# 取说有的评论及回复

@all_comments = @article.comment_threads

?

# 取第一级评论,对 article 的评论

@root_comments = @article.root_comments

?

判断一个评论是否有回复

@comment.has_children?

?

# 取一个评论的所以回复数量

@comment.children.size

?

# 取一个评论的所以回复按lft排序,正序{:parent_id=> :id}

@comment.children

?

# 取被评论对象

?@comment.commentable

热点排行