[RUBY] [Rails withdrawal] Create a simple withdrawal function with rails

[Rails withdrawal] Create a withdrawal function with rails

Prerequisites

Model: User model Controller: Users controller Routing: resources: describe users

Implementation process design before adding functions

(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.

Let's actually do it!

Tinker with Users_controller.rb

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

Tinker with view

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

[Rails withdrawal] Create a simple withdrawal function with rails
Create an EC site with Rails 5 ⑨ ~ Create a cart function ~
Create pagination function with Rails Kaminari
[Rails6] Create a new app with Rails [Beginner]
Create a simple web application with Dropwizard
Create a simple on-demand batch with Spring Batch
Create a simple bar chart with MPAndroidChart
Make a login function with Rails anyway
[Rails] Let's create a super simple Rails API
[Rails 5] Create a new app with Rails [Beginner]
Create a simple search app with Spring Boot
Create a simple bulletin board with Java + MySQL
[Rails] rails new to create a database with PostgreSQL
Create a team chat with Rails Action Cable
Let's make a search function with Rails (ransack)
Create an EC site with Rails 5 ⑩ ~ Create an order function ~
Create a simple CRUD with SpringBoot + JPA + Thymeleaf ② ~ Screen and function creation ~
Create a SPA with authentication function with Rails API mode + devise_token_auth + Vue.js 3 (Rails edition)
Introduced graph function with rails
Create a playground with Xcode 12
Create a simple demo site with Spring Security with Spring Boot 2.1
Login function implementation with rails
Create a name input function
Tutorial to create a blog with Rails for beginners Part 1
[Rails] I tried to create a mini app with FullCalendar
Create a simple CRUD with SpringBoot + JPA + Thymeleaf ③ ~ Add Validation ~
[Rails DM] Let's create a notification function when DM is sent!
[Rails] Create an email sending function with ActionMailer (complete version)
A series of steps to create portfolio deliverables with Rails
Tutorial to create a blog with Rails for beginners Part 2
Tutorial to create a blog with Rails for beginners Part 0
Create a simple DRUD application with Java + SpringBoot + Gradle + thymeleaf (1)
Create a Vue3 environment with Docker!
Create portfolio with rails + postgres sql
Add a search function in Rails.
Preparing to create a Rails application
[Rails Tutorial Chapter 5] Create a layout
Implemented mail sending function with rails
[Rails] Creating a new project with rails new
[Rails] Implementation of user withdrawal function
Implement simple login function in Rails
Create a new app in Rails
Create a filtering function using acts-as-taggable-on
I made a simple recommendation function.
Create My Page with Rails devise
Create exceptions with a fluid interface
Create a Maven project with a command
Create a simple web server with the Java standard library com.sun.net.httpserver
[Rails] A simple way to implement a self-introduction function in your profile
[Rails] I made a simple calendar mini app with customized specifications.
Create a simple CRUD with SpringBoot + JPA + Thymeleaf ④ ~ Customize error messages ~
I want to add a browsing function with ruby on rails
[Implementation procedure] Create a user authentication function using sorcery in Rails
(Ruby on Rails6) Create a function to edit the posted content
I tried to make a group function (bulletin board) with Rails
[Rails] Create an evaluation function using raty.js
Create a jar file with the command
Create Rails 6 + MySQL environment with Docker compose
Create a GUI JSON Viewer with Ruby/GTK3
Create a MySQL environment with Docker from 0-> 1
Create a temporary class with new Object () {}