Model: User model Controller: Users controller Routing: resources: describe users
(1) Acquire a record using the User id as a key, as in the case of adding the posting function. (2) Delete the record using the destroy method.
users_controller
class UsersController < ApplicationController
def destroy
@user = User.find(params[:id]) #Get information with a specific id
@user.destroy
flash[:success] = 'The user has been deleted.'
redirect_to :root #If the deletion is successful, return to the root page
end
end
erb:〇〇.html.erb
<%= link_to "Withdraw",user_path(current_user.id), class: "destroy-user",method: :delete %>
<%#here,(current_user.id)Pass the login user's id as an argument!
That's it! I couldn't make an advanced withdrawal function yet ... For the time being! !! Once with this!
Recommended Posts