1
내 앱에서 댓글은 사진에 속하므로 댓글을 삭제하는 방법을 추가하려고합니다.파괴 작업을 사용한 레일스 라우팅
routes.rb
resources :photos do
resources :comments
end
CommentsController
def destroy
@comment = Comment.find(params[:id])
@comment.destroy
end
사진/show.html.erb
<% @photo.comments.each do |comment| %>
<%= comment.body %></p>
<p><%= link_to 'Remove comment', comment, :confirm => 'Are you sure you want to remove this comment? This cannot be undone.', :method => :delete %></p>
<% end %>
오류는 undefined method 'comment' for #<Photo:0x10ace9270>
입니다. 내가 잘못 여기 어디로 갔는지
rake routes | grep comment
photo_comments GET /photos/:photo_id/comments(.:format) {:action=>"index", :controller=>"comments"}
POST /photos/:photo_id/comments(.:format) {:action=>"create", :controller=>"comments"}
new_photo_comment GET /photos/:photo_id/comments/new(.:format) {:action=>"new", :controller=>"comments"}
edit_photo_comment GET /photos/:photo_id/comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
photo_comment GET /photos/:photo_id/comments/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /photos/:photo_id/comments/:id(.:format) {:action=>"update", :controller=>"comments"}
DELETE /photos/:photo_id/comments/:id(.:format) {:action=>"destroy", :controller=>"comments"}
누구에게로 생각을 :
은 내가 comment
의 경로를 확인할 때 내가 얻을 수 있기 때문에 내가 제대로 내 경로 설정을하지 않을 수 있습니다 생각하십니까? 감사.
밤! 네, 그 트릭을했습니다. 나는 나의 노선이 그 때 좋다는 것을 짐작한다. 도와 주셔서 감사합니다! –
왜냐하면 그는 @photo를 통과했기 때문입니다. 주석은 사진 아래에 중첩되어 있기 때문에. –