I am using Devise gem to authenticate users for the first time. I can register, log out, log in and edit user accounts without problems, but deleting accounts does not work! When I click the delete button, a JS confirmation appears asking if I want to delete, click "Yes" ... and then redirected to the user's show page. The user account is not corrupted.
In 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>
In my UserController:
def destroy
@user = User.find(params[:id])
@user.destroy
if @user.destroy
redirect_to root_path
end
end
I am still reeling about Rails routing, but on my .rb routes I have:
devise_for :users, :controllers => { registrations: 'registrations' }
as well as:
resources :users
And when I start the rake routes, there are two routes that I think can be connected:
DELETE /users(.:format) registrations
DELETE /users/:id(.:format) users
, - , , . !