LoginSignup
6
5

More than 5 years have passed since last update.

MySQLを指定してrails newし、rails serverするまでの覚書

Posted at

たまに新規でアプリを作ろうとすると忘れてるので覚書です。

初心者がとりあえず、railsのアプリを作成して立ち上げる事を想定しています。
コマンドの細かいオプション等は省いています。

rails new

rails newする時、よく使うと思われるのが下記のオプション

rails new rails_app -d mysql -B
  • rails new アプリ名でrailsアプリの標準ファイルを生成します。
  • オプション-d データベース名は、データベースを指定してアプリを作成する。デフォルトだとsqliteになっています。
  • オプション-Bは、bundle installを自動実行しないオプション。Gemfileを編集してからbundle installしたい場合に指定します。

詳しくは下記のリンク参照
http://railsdoc.com/rails

bundel install

rails newするとrailsの基本フォルダが出来ます。
Gemfileを編集したい場合は、編集しbundle installして下さい。

bundle installするには、まず先ほど作ったアプリの直下に移動します。

cd rails_app

bundle installを実行します。

bundle install

DB作成

database.ymlに書いてあるdbを作成します。

rake db:create

-d mysqlをしたので、database.ymlはmysqlの設定で作られています。

rails s

サーバーを立ち上げましょう。

rails s

デフォルトだとポート3000でサーバーが起動するので、下記にアクセスして完了です。

http://localhost:3000
6
5
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
6
5