rails 3 - link_to 销毁不工作 [英] rails 3 - link_to to destroy not working

查看:42
本文介绍了rails 3 - link_to 销毁不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个指向我的用户控制器的销毁链接,我也在使用设计.

I am trying to create a destroy link to my users controller, I am also using devise.

这是我的代码 -

<%= 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

The link translates to localhost:3000/users/10

当点击这会打开用户显示而不是删除他们

When clicked this opens the users show instead of deleting them

有什么想法吗?

推荐答案

破坏性操作应该作为表单提交来执行 - http://www.w3.org/2001/tag/doc/whenToUseGet.html#checklist

Destructive actions should be performed as a form submission - http://www.w3.org/2001/tag/doc/whenToUseGet.html#checklist

使用 button_to(传递一个 :method => :delete)并适当地设置按钮样式.

use button_to (passing a :method => :delete) instead and style the button appropriately.

这篇关于rails 3 - link_to 销毁不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆