Ruby on rails 如何在Ember.js中使用ruby作为树宝石?
有关的创业板是: 我使用acts_as_树作为在我的应用程序上嵌套和输出评论的方法。以下代码位于_comment.html.erb中,运行良好Ruby on rails 如何在Ember.js中使用ruby作为树宝石?,ruby-on-rails,ember.js,ember-data,acts-as-tree,Ruby On Rails,Ember.js,Ember Data,Acts As Tree,有关的创业板是: 我使用acts_as_树作为在我的应用程序上嵌套和输出评论的方法。以下代码位于_comment.html.erb中,运行良好 <div id="comment_<%= comment.id %>"> <%= comment.body %> => <%= comment.children.length %> replies <%= render :partial => 'comments/comment',
<div id="comment_<%= comment.id %>">
<%= comment.body %> => <%= comment.children.length %> replies
<%= render :partial => 'comments/comment', :collection => comment.children %>
</div>
我想我的问题有点宽泛,但我一直在研究自指关系,但因为我不太确定acts_as_tree本身是如何工作的,所以我没有成功地实现这些解决方案。我可能一次做的太多了;以下是我非常感谢您的帮助:
如何正确序列化acts_as_树功能,以便Ember能够读取它
class Comment < ActiveRecord::Base
extend ActsAsTree::TreeView
acts_as_tree :order => 'created_at'
belongs_to :post
belongs_to :user
def commented_by
self.user.username
end
end
class CommentSerializer < ActiveModel::Serializer
embed :ids, include: true
attributes :id, :parent_id, :body, :created_at, :updated_at, :post_id, :user_id, :commented_by
belongs_to :post
end
App.Comment = DS.Model.extend({
parentID: DS.attr('number'),
body: DS.attr('string'),
createdAt: DS.attr('date'),
updatedAt: DS.attr('date'),
postID: DS.attr('number'),
userID: DS.attr('number'),
commentedBy: DS.attr('string'),
post: DS.belongsTo('post', {async: true}),
// parent: DS.belongsTo('comment', {async: true}),
// children: DS.hasMany('comment', {async: true})
});