[Rails withdrawal] Create withdrawal function with rails
Model: User model Controller: Users Controller Routing: describe resources :users
Implementation process design before adding functions
(1) Similar to the case where the posting function is added, records are acquired using the User id as a key ② Delete that record using the destroy method
Let’s do it!
messing with Users_controller.rb
class UsersController <ApplicationController def destroy @user = User.find(params[:id]) # Get information with specific id @user.destroy flash[:success] ='The user has been deleted. ' redirect_to :root #Return to root page if successful end end
messing with the view
<%= link_to "leave", user_path(current_user.id), class: "destroy-user",method: :delete %> <%# Here, pass the id of the logged-in user in the argument in (current_user.id)!
That’s it! I couldn’t create an advanced unsubscribe function yet… For the time being! !! Once with this!