This time I will summarize the basics when launching a new application with ruby on rails.
As a premise, the version of rails is 6.0.0 and the database uses a tool called MySQL.
#Move directory % cd ~/Directory name where you want to create an app #Create a new app(App name chochiku)、-Created by explicitly using MySQL with the d option % rails _6.0.0_ new chochiku -d mysql #Move to the created chochiku directory % cd chochiku
By typing the above code in the terminal, a new application will be launched.
Use the command to create the database for your app, but before you do that, you need to make a few settings related to the database.
Database settings are described in database.yml.
Write encoding: utf8mb4 under default in database.yml encoding: change to utf8
Then execute the following command to create the database
% rails db:create
Rails applications require a model that interacts with the database.
#Create Expense model % rails g model expense
When you create the above model, a migration file will be created in a directory called db / migrate at the same time. Edit this migration file to determine the information to save in the table.
class CreateExpenses < ActiveRecord::Migration[6.0] def change create_table :expenses do |t| t.string :name t.integer :shuppi t.timestamps end end end
For example, the code t.string: name is of type string and adds a column called name to the table.
Editing the migration file does not mean that you have made any changes to the table. You need to perform the migration there. You can execute the migration by executing the following command.
% rails db:migrate
With the above, we have created one model of the application and a table linked to that model. Actually, from now on, we will create an application by creating controllers, routings, and views linked to this model. That's all for the time being as the basis for creating a new application.