0
1

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.

Rails + Sass + Bootstrapで動く最小限の基盤

Last updated at Posted at 2018-07-20

これは何?

下記のような人に有効な、基盤を作るためのレシピです。

- gemはlocalでプロジェクト毎に使い分けたい
- githubで基本的に管理したい
- turbolinksは不明なエラーを招くので回避したい
- envでバージョン管理したい
- dbはmysqlを利用したい
- デザインにはbootstrapを利用したい

※ 至らない点はご指摘願います。

前提

- rbenv
- bundler
- ターミナルでの作業です。

実行環境

- ruby --version
    - 2.4.0
- rbenv --version
    - 1.1.1
- macOS High Sierra
    - 10.13.4
- bundler --version
    - 1.16.3

Gem環境整備

- bundle init
source "https://rubygems.org"

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

gem "rails"
gem "rspec"
gem "dotenv-rails"
gem "bootsnap"
gem "listen"
gem "mysql2"
gem "bootstrap-sass"
gem "jquery-rails"
gem "jquery-ui-rails"
- bundle install --path=vendor/bundle
- 次回以降はbundle installでOK

Git環境整備

- git init
- git remote add origin {{レポジトリ}}
- vim .gitignore
# Ignore bundler config.
/.bundle
/vendor/bundle

# Ignore log and temp.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore ENV.
.env*
!.env.sample


# Ignore master key for decrypting credentials and more.
/config/master.key

Rails整備

- rails new . -d mysql -T -G -skip-turbolinks
- mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss
- vim app/assets/stylesheets/application.scss

@import "bootstrap-sprockets";
@import "bootstrap";
- vim app/assets/javascripts/application.js

▼ 前

//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require_tree .

▼ 修正後

//= require rails-ujs
//= require activestorage
//= require jquery3
//= require bootstrap-sprockets
//= require_tree .

ENV整備

- touch .env.sample
- vim .env.sample
DATABASE_NAME=
DATABASE_USERNAME=
DATABASE_PASSWORD=
- cp .env.sample .env
- .envに環境情報記載

DATABASE整備

- vim config/database.yml
    - username: <%= ENV['DATABASE_USERNAME'] %>
    - password: <%= ENV['DATABASE_PASSWORD'] %>
    - database: <%= ENV['DATABASE_NAME'] %>
- bundle exec rails db:create
- bundle exec rails db:migrate

実行

- bundle exec rails server
- bundle exec rails generate controller ~~
- bundle exec rails generate model ~~
- bundle exec rails generate migration ~~

ファイル

0
1
1

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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?