Reputation: 961
I am trying to add ability to delete Wallet model in my User panel. However for some reason Rails reads it as a GET method and rise this error:
No route matches [GET] "/wallets/1"
My view file:
= link_to 'Remove wallet', wallet_path(@wallet), method: :delete, data: { confirm: 'Are you sure?' }
my wallets controller:
class WalletsController < ApplicationController
def create
@wallet = current_user.wallets.create(wallet_params)
if @wallet.save
redirect_to wallets_index_path
flash[:notice] = "New wallet has been added successfully"
else
render 'home/wallets_new'
flash[:alert] = "Your wallet could not be added. Please try again"
end
end
def destroy
@wallet.delete
redirect_to wallets_index_path, notice: 'Post has been deleted successfully'
end
routes:
devise_scope :user do
authenticated :user do
root to: 'home#wallets_index', as: :unauthenticated_root
resources :wallets, only: [:create, :destroy]
end
unauthenticated :user do
root to: 'home#index', as: :authenticated_root
end
end
and rake routes:
wallets POST /wallets(.:format) wallets#create
wallet DELETE /wallets/:id(.:format) wallets#destroy
I am not sure how to handle this error since I explicitly told Rails to use DELETE method via method: :delete in my link_to helper. How can I fix this?
Upvotes: 0
Views: 106