LoginSignup
0
2

More than 5 years have passed since last update.

基礎Ruby on Rails #02 Chapter1 アプリケーションの新規作成

Last updated at Posted at 2018-09-13

基礎Ruby on Rails #01 Chapter1 Rails開発環境の構築(WSL)
基礎Ruby on Rails #03 Chapter1 ディレクトリ構造・コントローラ・アクション・ビューの作成

アプリケーションの新規作成

rails newコマンド

$ cd ~/rails
$ rails new asagao -BCMT --skip-coffee -d sqlite3
  • rails new コマンドのオプション
    • -B bundleコマンドを実行しない。
    • -C Action Cableのファイル群を生成しない。
    • -M Action Mailerのファイル群を生成しない。
    • -T テスト関連のファイル群を生成しない。
    • --skip-coffee CoffeeScriptを使用しない。
    • -d データベースの種類を指定する。

Gemfileの修正(本に載っていない)

railsサーバーを起動すると以下のように怒られるので、Gemfileを編集する。

There was an error while trying to load the gem 'uglifier'. (Bundler::GemRequireError)
Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes.

Gemfileの以下のコメントアウトを外して、mini_racerを使えるようにする。(node.jsをインストールしてもOKらしい)

Gemfile
gem 'mini_racer', platforms: :ruby

bundle lockコマンドの実行(macOS, WSL/Ubuntu)

$ cd asagao
$ bundle lock --add-platform x64-mingw32 x86-mingw32
(省略)
Writing lockfile to /mnt/c/Users/tseno/Desktop/rails/asagao/Gemfile.lock
  • Gemfile末尾の以下の環境で動かすために、上記のbundle lockコマンドを実行する。MinGW環境で動かさないのであればGemfileから削ってもよい。
Gemfile
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

bundle installコマンドの実行

必要なGemパッケージをインストールする。

$ bundle install

アプリケーションの起動

$ bin/rails s

http://localhost:3000/ を開く。

image.png

参考
改訂4版 基礎 Ruby on Rails (IMPRESS KISO SERIES)

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