0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

React + Rails API 環境構築 ③Rails側の設定 Rails new,.gitignoreファイルの作成まで

Last updated at Posted at 2021-06-29

概要

  • 1からSPAアプリケーションの環境を作っていくので、その手順を残す

参考資料:【Rails】Rails6でAPIモードの環境構築をしっかりやる

環境情報

  • ruby : 2.6.6
  • rails : 6.1.4

バックエンド環境構築

1. Rails初期設定

  • プロジェクトのルートディレクトリにバックエンド用のディレクトリを作成
$ mkdir backend
  • rails new1で雛形を作成
  • バージョンは参考書のバージョンと合わせています現在の最新バージョン(マイナーバージョンまで)
$ rails _6.1.4_ new . -d mysql --api
  • giboで.gitignoreの雛形を作成

.gitignoreファイルを自動で生成してくれるライブラリがgibo(とはいえ中身は理解して書き換える必要があるが)
参考:【Rails】.gitignoreの設定について
参考2:ちょっと待った! Railsでgitリポジトリから除外すべきでないファイル:Gemfile.lockとdb/schema.rb

$ brew install gibo
$ gibo dump Rails > .gitignore

めっちゃ内容ないけどこれでサーバーサイドの最初の最初の設定は終わり。。。
ここまでで一旦commit(実際はcros用のgemもインストールする必要はあるがとりあえずcommit)

まとめ

  • .Gemfile.Gemfile.lock.gitignoreファイルに含めない
  • rails new-apiを指定することでAPIモード2に必要なファイルのみを作成する

注釈

  1. railsプロジェクトを新規で作成するときに使用するコマンド。様々なオプションがある 参考:Rails newまとめ

  2. フロント側から呼び出すためのリソースを定義するAPIを作成するためのモード。railsではオプションをつけるだけでAPIに必要なgemとディレクトリのみを作成することができる

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?