essentially I have a category that you can add comments to, this category shows a lists of tasks. When You add comments you have the ability to reply to said comment, when you do so and hover the reply link you’ll see something much like:
http://localhost:3000/categories/2/category_comments/new?parent=6
We then take that id, pass it to the reply forum and then assign it to the ancestry string in the database to “nest” the reply. The problem is, the parent id is not being passed to the form. The form’s hidden field is blank. Why? We can walk the path this id should take in the following code.
categories_controller
def show
@category = Category.find(params[:id])
@category_comment = @category.category_comments.build
end
This shows the comment on the category page, and passes the parent_id of the comment your replying to, to the form.
When we click reply, we trigger the category_comments#new and #create methods shown below.
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
update:
this is no longer a form issue it is a controller issue, dealing with passing the parent_id to the form.
Try this: