LoginSignup
0
1

More than 1 year has passed since last update.

【Rails】アプリ 新規作成 サーバー起動 手順

Posted at

新規アプリ作成〜サーバー起動まで最短で行う方法を記述してます:pencil2:

環境

Ruby 3.0.2
Rails 6.1.4
MySQL 5.6

※環境を合わせると、エラー最小限で進められると思います:thumbsup:

新規アプリ作成

MySQLを使用する場合

$rails new <アプリ名を記入> -d mysql

sqlite3を使用する場合

$rails new <アプリ名を記入>

データベース設定

config/database.ymlで以下を設定する

database.yml
default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root ←MySQLのユーザー名がrootでない場合は変更する
  password: "<MySQLのパスワードを記入>"
  socket: /tmp/mysql.sock

development:
  <<: *default
  database: <アプリ名>_development

データベース作成

以下のコマンドを実行

$ rails db:create

以下が表示されればOK

Created database '<アプリ名>_development'
Created database '<アプリ名>_test'

サーバー起動

①以下のコマンドを実行

$ rails s

②GoogleCrome等で、localhost:3000を開いて、以下の画面が表示されれば完璧:slight_smile:
スクリーンショット 2021-07-28 15.05.10.png

参考資料

備考

最短で起動したかったので、自分で記事を作成してみました。
不備などあれば教えていただけますと助かります:pray:

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1