Noroute matches [GET]의 원인과 해결 방법
잘못
post/index 브라우저에서post 컨트롤러의destroy 동작을 실시한 결과 다음과 같은 오류가 발생했습니다.
잘못된 곳
<%= link_to("削除", "/posts/#{@post.id}/destroy", {method: "delete"}) %>
해결책
일단 라크 루트로 확인을 해볼게요.
rake routes
posts_create POST /posts/create(.:format) posts#create
GET /posts/:id/edit(.:format) posts#edit
POST /posts/:id/update(.:format) posts#update
POST /posts/:id/destroy(.:format) posts#destroy
해결책
루스랑 방법을 바꿔서 해결했어.
① POST를 DELETE로 변경
routes에서 POST/posts/: id/destroy (.:format) 가DELETE/posts/: id/destroy (.:format) 로 변경됨
참고 자료: https://railsguides.jp/routing.html
②link_button toto로 변경
<%= button_to("削除", "/posts/#{@post.id}/destroy",method: :delete) %>
참고 자료: https://qiita.com/y-temp4/items/2d50feb3ff0d65acdf67메모지
link_to부터 button.to로 변경된 후 View는 이렇게 됩니다.
Reference
이 문제에 관하여(Noroute matches [GET]의 원인과 해결 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/peco4107/items/9b852100e0d2f8e57dd4텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)