1
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 5 years have passed since last update.

Railsで新規ファイルの作成までの流れ

Posted at

【概要】

アプリケーションを作成して、Gitで管理するところまで

【目標】

  • Ruby on Railsのバージョンを変更する
  • Gitの管理下に置く

新規アプリケーションの準備

Railsのバージョンを5.0.7.2にして開発

ターミナル
$ cd ~  # ホームディレクトリに移動
$ gem install rails --version="5.0.7.2"

gemの変更を反映

ターミナル
$ rbenv rehash

アプリケーションを作成しよう

rails newコマンドで新しいアプリケーションを立ち上げ

  • バージョン指定をしてrails newをすること
  • -d mysqlのオプションをつけること
  • DB管理はMySQLで行う
ターミナル
$ cd   #ホームディレクトリに移動
$ cd projects  #projectsディレクトリに移動
$ rails _5.0.7.2_ new chat-space -d mysql  #必ず左記の様にバージョン指定を行ってrails newコマンドを実行してください。
$ cd chat-space  #chat-spaceディレクトリに移動
$ rails db:create  # データベースを作成

不要なファイルを生成しないようにする

'rails g'コマンドでコントローラを作成すると、生成したファイルに対応したスタイルシート・ヘルパー・Javascript・アプリケーションをテストするためのファイルが同時に生成される。今回は不要。

config/application.rb
# 省略
module ChatSpace
  class Application < Rails::Application
    config.generators do |g|
      g.stylesheets false
      g.javascripts false
      g.helper false
      g.test_framework false
    end
  end
end

GitHubで管理

ローカルリポジトリの作成

GItHub Desktopから,該当のアプリのローカルリポジトリを作成
▷左上の「Current Repository」→「Add」→「Add Existing Repository」を選択
▷対象〇〇を選択し「Add Repository」をクリック
▷ローカルリポジトリにある全てのファイルを選択してコミットしましょう。
※その際のコミットメッセージは、最初のコミットなので「Initial commit」としておく。

リモートリポジトリを作成

コミットしたら、リモートリポジトリに反映させましょう。
GitHub Desktop では、Publish ボタンを押すとリモートリポジトリが作られていない場合にリモートリポジトリも作ってくれます。

以下のようなモーダルが表示され、リモートリポジトリを作成できます。
非公開にする必要がない場合、今回は[Keep this code private]のチェックは外す。

▷[Publish repository]ボタンをクリックすると GitHub のリモートリポジトリが作成できます。
▷GitHub の Your repositories の欄に git-app があれば上手く行っています。
▷適宜、ブランチも作成する

.gitignoreを編集

.gitignoreは、コミットしたくないファイル・ディレクトリを指定できる設定ファイルです。
画像投稿機能がある場合など、画像データがGitHubにコミットされないようにする。
▶画像が保管されるpublic/uploadsディレクトリを.gitignoreに追加

ディレクトリ名/.gitignore
# 末尾に次の記述を追加
public/uploads/*

以上です。

1
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
1
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?