This article explains how to interact with model databases using the Rails console (rails c).
Creating Data (Create/Insert)
Use the create method to create new data. This creates a model instance and saves it to the database in one operation.
Userinfo.create(name: "hoge")
Explanation: The create method executes in one step what would normally require creating an instance with the new method and saving it with the save method.
Selecting Data (Select)
To select data, use methods such as all or find.
# Get all records
Userinfo.all
# Get the name attribute of the record with ID 3
Userinfo.find(3).name
# => "hoge"
Note: The find method retrieves the record with the specified ID.
Updating Data (Update)
Use the update method to update data.
Userinfo.find(3).update(name: "fuga")
Explanation: Retrieve a specific record with the find method, then change its attribute values with the update method.
Deleting Data (Delete)
Use the delete or delete_all methods to delete data.
# Delete a specific record
Userinfo.find(3).delete
# Delete all records
Userinfo.delete_all
Note: The delete method deletes only the specified record, while the delete_all method deletes all records.