加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何使用Rails应用程序中的form_for发布以销毁

发布时间:2020-12-17 03:55:37 所属栏目:百科 来源:网络整理
导读:在我的Rails应用程序中,我希望我的用户在销毁自己的帐户之前输入他们的密码. 所以在我的routes.rb中我将它添加到我的用户资源: resources :users do member do get :terminate endend 在我的terminate.html.erb中,我有这个简单的形式: %= form_for(:user,:
在我的Rails应用程序中,我希望我的用户在销毁自己的帐户之前输入他们的密码.

所以在我的routes.rb中我将它添加到我的用户资源:

resources :users do
  member do
    get :terminate
  end
end

在我的terminate.html.erb中,我有这个简单的形式:

<%= form_for(:user,:controller => "users",:action => "destroy",:html => {:method => "delete"}) do |f| %>

  <%= f.label :password %><br/>
  <%= f.password_field :password %>

  <%= f.submit "Terminate account" %><br/>

<% end %>

在我的users_controller.rb中我有这个:

def terminate
  @user = User.find(params[:id])
  @title = "Terminate your account"
end

def destroy

  # make sure entered password is correct etc...

  @user.destroy
  flash[:success] = "Your account was terminated."
  redirect_to root_path
end

但是,当我点击提交时,我收到此错误:

No route matches [DELETE] "/en/users/7/terminate"

我在这里错过了什么?

谢谢你的帮助.

解决方法

这应该工作:

<%= form_for @user,method: :delete do |f| %>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读