command
% rails _6.0.0_ new application -d mysql
-The version is specified in "6.0.0".
-"Application" indicates the name of the application you want to create.
-By adding the option "-d mysql"
Use MYSQL as a data management tool.
config/database.yml
default: &default
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password:
socket: /tmp/mysql.sock
You can set the encoding like "utf8".
command
% rails db:create
Create a database with the rails command.
config/route.rb
Rails.application.routes.draw do
root to: "notes#index"
end
The index action of notes_controller will be called when the root path is accessed.
config/application.rb
#abridgement
config.load_defaults 6.0
#Omission
config.generators do |g|
g.stylesheets false
g.javascripts false
g.helper false
g.test_framework false
end
Before creating a controller with the rails g command, set not to generate unnecessary files.
commnad
% rails g controller notes index
If you specify the action name after the controller name when creating the controller, ・ Index action is created in notes controller ・ Index.html.erb file is created in the notes folder of views
Recommended Posts