やる気スイッチ入れました。

トビタテ留学JAPAN1期, Canpath, 農業経営及び関連産業研究室, Bordeaux留学, フランス語, プログラミング, デザイン あたりに関して書いてます。

Railsでアプリケーション作成するときにやっておきたい設定一覧

アプリケーションを作成するときにやりたい設定をまとめてみる。
railsのバージョン指定からminitestレポーターまで

 

 アプリケーションの作成

 <terminal>

rails _4.2.2_ new application_name
 
cd application_name
 
git init
git add .
git commit -m "first commit"
git add origin master git@bitbucket.org:---------
git push -u origin master

 

この辺りでbitbucketの設定をしておいてレポジトリとリンクさせておく。 次に gemfile の設定を行う。 もともとのgemfileの中身を次のように書き換え

 

 
 
 
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.2'
gem 'bcrypt', '3.1.7'
gem 'bootstrap-sass', '3.2.0.0'
# Use sqlite3 as the database for Active Record
# Use SCSS for stylesheets
gem 'sass-rails', '5.0.2'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '2.5.3'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
 
# Use jquery as the JavaScript library
gem 'jquery-rails', '4.0.3'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks', '2.3.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '2.2.3'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '0.4.0', group: :doc
 
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
 
# Use Unicorn as the app server
# gem 'unicorn'
 
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
 
group :development, :test do
 # Call 'byebug' anywhere in the code to stop execution and get a debugger console
 gem 'byebug', '3.4.0'
 
 # Access an IRB console on exception pages or by using <%= console %> in views
 gem 'web-console', '2.0.0.beta3'
 
 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
 gem 'spring', '1.1.3'
 
 gem 'sqlite3', '1.3.9'
end
 
group :test do
 gem 'minitest-reporters', '1.0.5'
 gem 'mini_backtrace', '0.1.3'
 gem 'guard-minitest', '2.3.1'
end
 
group :production do
end

 

設定を反映する。

1
bundle install

サーバー立ち上げ

1
rails s

Heroku用の環境準備のためにgemfile に以下のコードをプラスする

1
2
3
4
5
group :production do
 gem 'pg', '0.17.1'
 gem 'rails_12factor', '0.0.2'
 gem 'puma', '2.11.1'
end

 

設定の反映

1
2
3
4
5
6
7
8
9
10
11
bundle install --without production
git commit -a -m "Update Gemfile.lock for Heroku"
heroku version
heroku login
heroku keys:add #Yes or no を聞かれるので Y
 
heroku create
git push heroku master
heroku open
 
heroku rename appname

 

コードを書いたりする際にやっておくこと。

ブランチの作成

1
2
git checkout master
git checkout -b branchname

ブランチのマージ

1
2
3
4
5
6
7
8
9
10
git add -A
git commit -m "your comment"
 
git checkout master
git merge branchname
 
git push
 
bundle exec rake test
git push heroku

minitest レポーター

test/test_helper.rb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
 
require 'rails/test_help'
 
require "minitest/reporters"
 
Minitest::Reporters.use!
 
 
class ActiveSupport::TestCase
 
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical
 
# order.
 
fixtures :all
 
 
# Add more helper methods to be used by all tests here...
 
end