ruby-on-rails - Rails:找不到删除方法。改为渲染 get 方法
问题描述
我正在尝试在我的用户面板中添加删除钱包模型的功能。但是由于某种原因,Rails 将其读取为 GET 方法并引发此错误:
没有路线匹配 [GET] "/wallets/1"
我的视图文件:
= link_to 'Remove wallet', wallet_path(@wallet), method: :delete, data: { confirm: 'Are you sure?' }
我的钱包控制器:
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
路线:
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
和耙路线:
钱包 POST /wallets(.:format) 钱包#create
钱包删除 /wallets/:id(.:format) 钱包#destroy
我不确定如何处理这个错误,因为我在我的 link_to 助手中明确告诉 Rails 通过 method: :delete 使用 DELETE 方法。我怎样才能解决这个问题?
解决方案
推荐阅读
- ruby - 在 Ruby 中循环遍历 Enumerator 的其余部分
- mysql - mysql表结构,更好的解决方案
- maven - 仅将 spring-boot-dependencies 导入为 pom 时无法解决 Spring Cloud 依赖关系
- go - 如何将最后一个 sql 行附加到列表而不替换 Golang 中的先前行
- c# - HttpClient PostAsync 不返回
- javascript - django: JavaScriptCataLog 中的 request.LANGUAGE_CODE 不返回显示的页面
- java - 语法错误,插入“AssignmentOperator 表达式”以完成表达式。为什么会这样?
- javascript - 在对象数组中搜索条目匹配变量并检查它是否与其他字段匹配
- r - 如何将对角线行转换为R中的单行?
- c# - 识别并保存来自浏览器 iOS 的流视频