※環境は、AWSのCloud9を使っています。
(1)Railsインストール
$ gem install rails -v 6.0.3
(2-1)yarnのインストール
$ source <(curl -sL https://cdn.learnenough.com/yarn_install)
(2-2)yarnがインストールできなかった場合
$ yarn install --check-files
(3)アプリの作成
$ rails _6.0.3_ new hello_app
(4)gemfileを一新する
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'rails', '6.0.3'
gem 'puma', '4.3.6'
gem 'sass-rails', '5.1.0'
gem 'webpacker', '4.0.7'
gem 'turbolinks', '5.2.0'
gem 'jbuilder', '2.9.1'
gem 'bootsnap', '1.4.5', require: false
group :development, :test do
gem 'sqlite3', '1.4.1'
gem 'byebug', '11.0.1', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
gem 'web-console', '4.0.1'
gem 'listen', '3.1.5'
gem 'spring', '2.1.0'
gem 'spring-watcher-listen', '2.0.1'
end
group :test do
gem 'capybara', '3.28.0'
gem 'selenium-webdriver', '3.142.4'
gem 'webdrivers', '4.1.2'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
(5)hello_appに移動する
$ cd hello_app/
(6-1)gemインストール
$ bundle install
(6-2)エラーが起こった場合
$ bundle update
(6-3)もう一度gemインストール
$ bundle install
(7)application_controller.rbの書き換え
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
def hello
render html: "hello, world!"
end
end
(8)routes.rbの書き換え
Rails.application.routes.draw do
root 'application#hello'
end
(9)ローカルサーバーへの接続を許可のためにconfig.hosts.clearをRails.application.configure do内に含める
config/environments/development.rb
config.hosts.clear
(10)サーバーの立ち上げ
$ rails server
(11)ブラウザに表示
(12)サーバーを閉じる
Ctrl + C

