前提・実現したいこと
掲示板アプリを作る段階で削除ボタンを作ろうとしたのですがエラーが出ます。
ボタン自体は作成出来たものの、ボタンを押すと以下のようにエラーが出てきます。
発生している問題・エラーメッセージ
Routing Error No route matches [DELETE] "/posts" Rails.root: /Users/oohirakatsuya/prac/bbs Application Trace | Framework Trace | Full Trace Routes Routes match in priority from top to bottom Helper HTTP Verb Path Controller#Action Path / Url Path Match root_path GET / posts#index posts_path GET /posts(.:format) posts#index POST /posts(.:format) posts#create new_post_path GET /posts/new(.:format) posts#new edit_post_path GET /posts/:id/edit(.:format) posts#edit post_path GET /posts/:id(.:format) posts#show PATCH /posts/:id(.:format) posts#update PUT /posts/:id(.:format) posts#update DELETE /posts/:id(.:format) posts#destroy rails_service_blob_path GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show rails_blob_representation_path GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show rails_disk_service_path GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show update_rails_disk_service_path PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update rails_direct_uploads_path POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
該当のソースコード
index.html.erb
<%= link_to "削除", posts_path, method: :delete, data: {confirm: "本当にいいですか?"}, class: "btn btn-danger" %>
routes.rb
Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root 'posts#index' resources :posts end
posts_controller.rb
def destroy @post = Post.find(params[:id]) @post.destroy redirect_to posts_path end
何が原因か分かる方がいましたら教えてくださいお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/21 06:40