Rails 3 - link_to 销毁不起作用

2023-11-21

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

这是我的代码 -

View

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

Routes

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

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

单击时,这将打开用户显示而不是删除它们

有任何想法吗 ?


破坏性行为应以表单提交的形式执行 -http://www.w3.org/2001/tag/doc/whenToUseGet.html#checklist

use button_to(通过一个:method => :delete) 并适当地设置按钮的样式。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Rails 3 - link_to 销毁不起作用 的相关文章

随机推荐