Rails — Scaffolding create and destroy tables

Stela Capsa
2 min readJul 13, 2021

Rails scaffolding is a command that creates controllers, model, views, routing, database migration, and some css.

Here is an example, let’s create a category table.

$ rails generate scaffold category

One simple command created a full chain of folders and files.

DB folder looks like that

controllers/categories_controller.rb

models/category.rb

views/categories/index.html.erb and the resst of the files CRUD

config/routes.rb

After adding the data in the db file categories, run

$ rake db:migrate

there is an other way to create scaffolding with data necessary.

$ rails generate scaffold category name:string 

It is more easier to fill up the tables, from the command, afterwards run

$ rake db:migrate

In case you want to delete the table run the command.

$ rails destroy scaffold category

Happy Coding!

--

--