-
Notifications
You must be signed in to change notification settings - Fork 0
start_project
irisAsh edited this page Jan 3, 2018
·
3 revisions
プロジェクト作成用に、任意のディレクトリに Bundle 環境を作成する。
ローカル環境の ruby のバージョンを指定する。
$ rbenv local 2.4.0
Gemfile の作成と Bundle 環境の初期化を行う。
$ rbenv exec gem install bundler
$ rbenv rehash
$ rbenv exec bundle init
ralis の Gem をインストールするために、 Gemfile を編集する。
source "https://rubygems.org"
gem “rails”, “5.1.3”
Rails をインストールする。
$ rbenv exec bundle install --path vendor/bundle
Rails プロジェクトを作成する。
$ rbenv exec bundle exec rails new learnrails --skip-bundle
プロジェクト作成用に作成した環境を削除する。
$ rm -f Gemfile
$ rm -f Gemfile.lock
$ rm -rf .bundle
$ rm -rf vender
.gitignoreの最下行にvender/bundleを追加する。
Gem をインストールする。
$ rbenv exec bundle install --path vendor/bundle
プロジェクトを起動する。
$ rbenv exec bundle exec rails server
Gemfile を編集し、pgの Gem をインストールする。
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
# Use postgresql as the databese for Active Record
gem 'pg'
$ rbenv exec bundle install --path vendor/bundle
config/database.ymlを編集し、利用する DB を Postgresql に指定する。
default: &default
adapter: postgresql
encoding: utf8
pool: 5
timeout: 5000
development:
<<: *default
database: learnrails_development
test:
<<: *default
database: learnrails_test
production:
<<: *default
database: learnrails_production
username: learnrails
password: <%= ENV['APP_DATABASE_PASSWORD'] %>
host: localhost
port: 5432
DB を作成する。
$ bin/rake db:create
Created database 'learnrails_development'
Created database 'learnrails_test'
Postgresql から確認する。
$ psql -U postgres
postgres=# \l
erubis, haml, hamlit, faml, slim とテンプレートエンジンは色々あるが、ここでは haml を利用することにする。 Gemfile に以下を追加。
gem "haml-rails"
Gem をインストール。
$ rbenv exec bundle install --path vendor/bundle