本質上,我有一個可以添加註釋的類別,此類別顯示任務列表。當您添加註釋,你必須回覆該註解的能力,當你這樣做和懸停回覆鏈接,你會看到的東西很像:祖先字符串不被確定
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