2012-09-14 39 views
0

本质上,我有一个可以添加注释的类别,此类别显示任务列表。当您添加注释,你必须回复该注解的能力,当你这样做和悬停回复链接,你会看到的东西很像:祖先字符串不被确定

http://localhost:3000/categories/2/category_comments/new?parent=6 

我们再取该ID,将它传递给答复论坛然后将其分配给数据库中的血统字符串以“嵌套”回复。问题是,父ID没有被传递给表单。表单的隐藏字段为空。为什么?我们可以在下面的代码中走这个id应该采用的路径。

categories_controller

def show 
    @category = Category.find(params[:id]) 
    @category_comment = @category.category_comments.build 
    end 

这表明类别页面的意见,并通过的PARENT_ID的评论你在回答,到窗体。

当我们点击回复时,我们触发下面显示的category_comments#new#create方法。

category_comments_controller

def new 
    @category = Category.find(params[:category_id]) 
    @category_comment = @category.category_comments.build(:parent_id => params[:parent_id]) 
    end 

    def create 
    @category = Category.find(params[:category_id]) 
    @category_comment = @category.category_comments.create(params[:category_comment].merge(:user_id => current_user.id)) 
    if @category_comment.save 
     redirect_to project_category_path(@category.project, @category), :flash => {:success => 'Created comment'} 
    else 
     redirect_to :back, :flash => {:error => 'Could not create comment'} 
    end 
    end 

更新:

这不再是一种形式问题,它是一个控制器的问题,处理传递PARENT_ID的形式。

回答

0

试试这个:

<%= link_to 'Reply', new_category_category_comment_path(@category.id, :parent_id => category_comment.id)%> 
+0

没有任何东西仍然没有 – TheWebs

0

您的模型中是否定义了has_ancestry?我认为没有它会有一个有效的解释,这不工作。

+0

排列方法会爆炸和页面不会呈现,但回答你的问题,是的,我做 – TheWebs

0

一些这神奇的是如何解决自身。我不知道如何或发生了什么,但它现在神奇地工作>>