2
2

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.

Ruby on Rails 初期構築

Last updated at Posted at 2018-09-26

Ruby on Rails 初期構築

バージョンは以下の通り
  • Bundler version 1.16.5
  • ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]

github にリポジトリ作成してクローン

$ git clone https://github.com/xxxx\rails_project

--

bundle 初期化

$ cd rails_project/
$ bundle init

でGemfileが生成されます。

Gemfile
$ cat Gemfile
# frozen_string_literal: true

source "https://rubygems.org"

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

gem "rails" # ←コメント外します。

bundle install
$ mkdir -p vendor/bundle
$ bundle install  --path ./vendor/bundle

/vendor/bundleに上記のGemfileのパッケージがインストールされて、Gemfile.lockが生成されます。


Rails プロジェクト生成
$ bundle exec rails new -B -d mysql -f .

Gemfileがrails用に上書きされます。ので再び

rails bundle install
$ bundle install
An error occurred while installing mysql2 (0.5.2), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'` succeeds before bundling.

mysql のエラーが表示されたら、

$ brew install mysql
$ bundle install
データベース作成&マイグレーション
database.yml
default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password: root
  host: 127.0.0.1

development:
  <<: *default
  database: RailsStudy_dev

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  <<: *default
  database: RailsStudy_test
$ bundle exec rails db:create
$ bundle exec rails db:migrate
ローカルサーバー起動
$ bundle exec rails server
http://localhost:3000/ へアクセス

スクリーンショット 2018-09-27 06.54.58.png

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?