我正在try 创建一个到我的用户控制器的销毁链接,我也在使用Desive.

这是我的密码-

看法

<%= link_to 'Delete User?', child, :confirm => "Are you sure you want to delete #{child.full_name}?", :method => :delete, :class => "user-additional", :style => "font-size:12px;font-weight:normal;" %>

控制器

def destroy
 if @user = User.find(params[:id])
  @user.destroy
  respond_to do |format| 
    format.html { redirect_to account_index_path } 
    format.xml { head :ok } 
  end
 end
end

路由

devise_for :users 
resources :users, :except => [:new]

链接转换为localhost:3000/users/10

单击此按钮将打开用户显示,而不是删除他们

有什么 idea 吗?

推荐答案

destruct 性行动应作为表格提交-http://www.w3.org/2001/tag/doc/whenToUseGet.html#checklist

改为使用button_to(通过:method => :delete),并适当设置按钮样式.

Ruby-on-rails相关问答推荐

如何在嵌套路由中使用Ruby on rails多态关联

Rails 7,Hotwire 动态表单,更新值不起作用

Ruby:如何通过谓词将一个集合拆分为 ruby​​ 中的两个集合?

如何验证 Rails 中的多态字段关联?

Rspec期望()与期望{}

Rails - Comment.count没有改变1

Rails 5:如何从数据库中删除列?

rake assets:precompile try 连接到数据库

使用 rails 3.1.0 和 ubuntu 安装 Nokogiri 1.5.0 时出错

从 Authlogic 迁移到 Devise

Rails 4,使用 ActiveRecord 的原始查询

RSpec 设置会话对象

我如何存根 find_each 以在 rails 3 中进行 rspec 测试

在 Controller 中调用模型方法

在 ruby​​ 中构建公钥时,是什么导致既不是 PUB key 也不是 PRIV key::nested asn1 错误?

如何让 ActiveAdmin 使用强参数?

Rails:进行不可逆转的迁移是不是很糟糕?

设计/Rails - 如何删除特定的 Flash 消息? (登录成功)

让 bundler 为不同的平台使用不同的 gem

Ruby 中的类别名