글과 댓글이 있고 표시할 URL이 /posts/1/comments/1
이라고 가정해 보겠습니다. 댓글 컨트롤러 삭제 메서드에서 해당 댓글을 삭제하는 링크를 만들고 싶습니다. 어떻게 해야 하나요?
<%= link_to 'Destroy', post_comment_path(@post, comment),
data: {:confirm => 'Are you sure?'}, :method => :delete %>
를 댓글 컨트롤러에 추가합니다:
def destroy
@post = Post.find(params[:post_id])
@comment = Comment.find(params[:id])
@comment.destroy
respond_to do |format|
format.html { redirect_to post_comments_path(@post) }
format.xml { head :ok }
end
end