本质上,我有一个可以添加注释的类别,此类别显示任务列表。当您添加注释,你必须回复该注解的能力,当你这样做和悬停回复链接,你会看到的东西很像:祖先字符串不被确定
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的形式。
没有任何东西仍然没有 – TheWebs