【发布时间】:2016-01-23 18:18:21
【问题描述】:
我第一次使用 Devise gem 对用户进行身份验证。我可以毫无问题地注册、注销、登录和编辑用户帐户,但删除帐户不起作用!当我点击删除按钮时,弹出JS确认询问我是否要删除,我点击是...然后我被重定向到用户的显示页面。用户帐户完好无损。
在views/devise/registrations/edit.html.erb:
<p>Unhappy? <%= button_to "Cancel my account", '/users/#{@user.id}', data: { confirm: "Are you sure?" }, method: :destroy, class: "btn btn-danger" %></p>
在我的用户控制器中:
def destroy
@user = User.find(params[:id])
@user.destroy
if @user.destroy
redirect_to root_path
end
end
我仍然对 Rails 路由感到不安,但在我的 routes.rb 中我有:
devise_for :users, :controllers => { registrations: 'registrations' }
还有:
resources :users
当我运行 rake 路由时,我认为可能关联的两条路由是:
DELETE /users(.:format) registrations#destroy
DELETE /users/:id(.:format) users#destroy
我很确定我在路线上做错了什么,但我看不出是什么。任何建议表示赞赏!
【问题讨论】:
标签: ruby-on-rails devise