2013-04-25 53 views
1

我正在創建一個應用程序,允許用戶對創建的項目發佈發表評論。我跟着這個Railscast來建立多態關聯。多態協會 - 刪除評論

每個教程的一切都很好,但我一直試圖在我的評論控制器中建立一個刪除方法,這樣可以刪除評論。我在我的評論控制器中創建了一個名爲destroy的方法。

評論是在我的項目發佈。部分評論是在項目頁面和發佈用戶的頁面上生成的。當我在項目頁面上刪除時,它工作的很好,但是當我嘗試從用戶頁面刪除時,我得到下面的結果。我該如何修復它,以便用戶可以刪除評論,無論他們是從項目頁面還是從他們自己的用戶頁面中刪除?

Unknown action 
The action 'show' could not be found for CommentsController 

comments_controller.rb

def destroy 
    @comment = Comment.find(params[:id]) 
    @comment.destroy 

    if @comment.destroy 
     redirect_to @commentable, notice: "Comment deleted." 
    end 
    end 

_comment.html.erb

<div class="comments">   
    <p><%= comment.content %></p> 
    <span> 
    By <%= link_to comment.user.name, comment.user %> <%= time_ago_in_words(comment.created_at) %> ago 

    <div class="pull-right"> 
<%= link_to "Destroy", [@commentable, comment], method: :delete, data: { confirm: 'Are you sure?' } %> 
</div> 
    </span> 
</div> 

的routes.rb

resources :comments 

resources :projects do 
    resources :comments 
    member do 
    get :following 
    end 
end 

回答

3

嘗試......

<%= link_to "Destroy", [@commentable, comment], method: :delete, data: { confirm: 'Are you sure?' } %> 
+0

還沒有工作。 – spl 2013-04-25 05:56:00

+0

顯示你的路線文件... – 2013-04-25 07:19:04

+0

添加到我的問題上面! – spl 2013-04-25 19:46:03