我刚开始使用继承的资源,并希望将其用于多态嵌套注释。我有几个可以评论的对象(文章、画廊等)。注释也可以嵌套。我将awesome_nested_set (parent_id、lft、rgt)与具有多态可评论列的注释模型结合使用。
控制器需要接收创建操作的AJAX请求(仅),并执行如下操作:
在/articles/12/comments/34上发布可以创建一个注释,其注释等于@项目(12),父级等于@注释(34)
/条款/12/评论/34
在/gallery/12/comments/34上发布可以创建一个注释,其注释等于@图片库(12),父评论等于@注释(34)
我有点不知道该从哪里开始。这是继承资源的好用例吗?
class CommentsController < InheritedResources::Base
respond_to :js, :only => :create
belongs_to :article, :cheat, :gallery, :video, :polymorphic => true
do
belongs_to :comments
end
def create
create! do |format|
# How in here do I build a comment so that it handles
polymorphism?
@comment.children.create(:commentable => @article or @cheat or
@something_generic?)
end
end
end 发布于 2010-11-30 22:33:25
嵌套注释是很困难的。Rails资源在将id传递给create操作时没有提供,因此我认为您不能以这种方式正确地将id发送到create操作。您可能需要在/comments/33/comments.选项中添加注释,这样就可以将评论发布到belong_to我不知道InheritedResources是否支持这一点。如果是这样的话,对象的创建就应该是自动的。你也可以参考像parent_url这样的东西。
https://stackoverflow.com/questions/4319286
复制相似问题