Rails Basic CRUD function implementation procedure scaffold


Summarize the steps to implement basic CRUD functionality using Ruby on Rails. CRUD is an acronym for Create, Read, Update, and Destroy.

Launch the app

In the terminal, use the rails command to create an app.

rails new blog_app -d postgresql

This command creates a new blog_app. I'm used to it, so I use postgreSQL as the database. If nothing is specified, sqlite3 will be the database. Then go to the root directory of the app (cd blog_app) and in the terminal

rails db:create

Enter to launch the database. Launch the server and check locally that the app is ready.

rails s


OK if the above screen appears. You can finish the server startup with ctrl + C.

CRUD function

Now that the app has been launched, we will implement the ability to post (create), read (read), update (update), and delete (delete) blogs. In fact, using the rails generator scaffold, it's done with just two commands.

rails g scaffold blog title:string content:text
rails db:migrate

With the first command, you can create Blog models, views, controllers and routers all at once. In this case, a string (character string) type instance variable title and a text (text) type instance variable content are created in the Blog model. The second command is needed to create a blogs table in the database.


Now let's summarize the model, view, controller and router code without using scaffold.

Recommended Posts

Rails Basic CRUD function implementation procedure scaffold
[Rails] Comment function implementation procedure memo
[rails] gem'payjp' implementation procedure
Rails search function implementation
Rails fuzzy search function implementation
Rails CRUD function implementation ② (edited and detailed this time)
[Rails 6] Implementation of search function
[Rails] Implementation of category function
Login function implementation with rails
[Rails] Implementation of tutorial function
[Rails] Implementation of like function
Rails CRUD function implementation ① (new addition, deletion this time)
[Rails 6] Pagination function implementation (kaminari)
[Rails] Implementation of CSV import function
[Rails] Asynchronous implementation of like function
[Rails] Implementation of image preview function
[Rails] About implementation of like function
[Rails] Implementation of user withdrawal function
[Rails] Implementation of CSV export function
[Rails] gem ancestry category function implementation
[Ruby on Rails] Comment function implementation
[Rails 6] Like function (synchronous → asynchronous) implementation
[Implementation procedure] Create a user authentication function using sorcery in Rails
[Ruby on Rails] Follow function implementation: Bidirectional
[Rails 6] Implementation of SNS (Twitter) sharing function
[Vue.js] Implementation of menu function Implementation version rails6
[Ruby on rails] Implementation of like function
[Vue.js] Implementation of menu function Vue.js introduction rails6
[Rails] I will explain the implementation procedure of the follow function using form_with.
[Rails] Implementation of search function using gem's ransack
Implementation of Ruby on Rails login function (Session)
[Rails 6] Implementation of inquiry function using Action Mailer
[Rails] Implementation of image enlargement function using lightbox2
[Rails 6.0] "Easy login" implementation procedure required for portfolio
[Rails] Category function
[JQuery] Implementation procedure of AutoComplete function [Java / Spring]
Rails follow function
Ruby on Rails Email automatic sending function implementation
[Rails / devise] Implementation of account information editing function / Procedure for changing redirect destination
Rails basic philosophy
[Rails] Implementation procedure when public / private functions are added to the posting function
[Rails] Notification function
Ruby on Rails <2021> Implementation of simple login function (form_with)
[Rails] Implementation of drag and drop function (with effect)
[Implementation procedure] Implement image upload function with Active Storage
Implementation of Ruby on Rails login function (devise edition)
[Rails] Implementation of multi-layer category function using ancestry "Preparation"
[Rails] Implementation of multi-layer category function using ancestry "seed"
[Rails] Implementation of SNS authentication (Twitter, Facebook, Google) function
Rails hashtag search implementation
Rails6 countdown timer implementation
Rails Action Text implementation
Follow function (Ajax) implementation
Implementation of search function
Rails Heroku deployment procedure
[rails] tag ranking function
Implementation of pagination function
Search function [copype implementation]
Rails, RSpec installation procedure
[Rails] Implementation of multi-layer category function using ancestry "Editing form"
[Order function] rails Order function implementation Confirmation screen will also be created ~