[RUBY] Make a family todo list with Sinatra

Introduction

@kirinri posted * Nice article --Qiita *, so let's get on it.

Completion screen

20200805.png

Ingenuity

When a user is deleted, the user's Todo is deleted.

main.rb


post '/destroy_user' do
  Todos.where('users_id = ?', params[:users_id]).destroy_all
  Users.find(params[:users_id]).destroy
  redirect to('/')
end

ʻActive record` is nice because you don't have to write SQL.

Round the corners of the item

style.css


.user_btn {
  height: 28px;
  background-color: #FFAD90;
  border-style: none;
  border-radius: 5px;
}

~~ The last 3 lines ~~ The last line is rounded Thank you to @scivola.

Postscript

If you delete a user, it will not be reloaded and the deleted user will remain in the drop-down list. 20200806.png If you add it to the list as that user, you will get an exception. 20200806error.png

main.rb


post '/create_todo' do
  begin
    Todos.create(body: params[:body],users_id: params[:users_id])
  rescue => e
  end
  redirect to('/')
end

I've added exception handling, but I don't think it's a compliment because it's just through.

Summary

Referenced site

Recommended Posts

Make a family todo list with Sinatra
Make a family todo list with Sinatra
Make a list map with LazyMap
Let's make a LINE Bot with Ruby + Sinatra --Part 2
Let's make a LINE Bot with Ruby + Sinatra --Part 1
I want to make a list with kotlin and java!
Make a digging maze with Ruby2D
Make a slideshow tool with JavaFX
Make a Christmas tree with swift
Make a garbage reminder with line-bot-sdk-java
Make a typing game with ruby
Let's make a Christmas card with Processing!
Draw a graph with Sinatra and Chartkick
Let's make a smart home with Ruby!
Make a login function with Rails anyway
[docker] [nginx] Make a simple ALB with nginx
Make a site template easily with Rails
Create Scala Seq from Java, make Scala Seq a Java List
Let's make a search function with Rails (ransack)
[Android] I tried to make a material list screen with ListView + Bottom Sheet
Make System.out a Mock with Spock Test Framework
Run Scala with GraalVM & make it a native image
How to make a factory with a model with polymorphic association
Practice making a simple chat app with Docker + Sinatra
[Java basics] Let's make a triangle with a for statement
[Personal application work memo] Make a calendar with simple_calendar
Make a reflection utility ②
Make a reflection utility ③
Make a reflection utility ①
[Beginner] Try to make a simple RPG game with Java ①
I want to make a function with kotlin and java!
Make a simple CRUD with SpringBoot + JPA + Thymeleaf ① ~ Hello World ~
Learning Ruby with AtCoder 13 How to make a two-dimensional array
Let's make a simple API with EC2 + RDS + Spring boot ①
Make a simple CRUD with SpringBoot + JPA + Thymeleaf ⑤ ~ Template standardization ~