2012-09-14 76 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

一些這神奇的是如何解決自身。我不知道如何或發生了什麼,但它現在神奇地工作>>