In my Rails app I want my users
to enter their password before destroying their own account.
So in my routes.rb I added this to my user
resource:
resources :users do
member do
get :terminate
end
end
In my terminate.html.erb I have this simple form:
<%= 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 %>
In my users_controller.rb I have this:
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
However, when I click submit I get this error:
No route matches [DELETE] "/en/users/7/terminate"
What am I missing here?
Thanks for any help.
This should work:
<%= form_for @user, method: :delete do |f| %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With