デモアプリ
ソフトウェア | バージョン | 備考 |
---|---|---|
OS X | 10.8.5 | |
ruby | 2.0.0 | |
rvm | 1.24.0 | |
rbricks | 2.0.5 | |
heroku-toolbelt | 3.6.0 |
$ rvm install ruby-2.0.0-p247
$ rvm use ruby-2.0.0
$ rvm gemset create sukusuku
$ rvm use ruby-2.0.0@sukusuku
$ gem install railsbricks
$ gem install rails --version=4.0.4
$ git clone https://github.com/LeanEC/mvp_smoke_tester.git
$ bundle
$ rake db:migrate
$ rake db:seed
$ rails s
Gemfile編集
gem 'i18n_generators'
日本語ファイル生成
$ bundle
$ rails g i18n ja
モデルの日本語対応
config/locales/translation_ja.yml
ja:
activerecord:
models:
user: ユーザー
attributes:
user:
admin: 管理者
email: eメール
username: ユーザー名
password: パスワード
password_confirmation: パスワード再確認
current_password: 現在のパスワード
group :test, :development do
gem "rspec-rails", '~> 2.14.1'
gem "guard-rspec"
gem "factory_girl_rails"
gem "spring"
gem "guard-livereload", require: false
gem "spring-commands-rspec"
end
_spec/spec_helper.rb_の最後に以下を追加
config.before(:all) do
FactoryGirl.reload
end
$ guard init rspeclivereload
生成されたGuardfileから以下の行を変更する
変更前
guard :rspec do
変更後
guard :rspec, cmd: 'spring rspec -f doc' do
group :test do
gem "cucumber-rails", require: false
gem "database_cleaner"
gem "guard-cucumber"
end
Capybaraのsave_and_open_page実行時にブラウザに出力するようにする
group :test do
gem "capybara", '~> 2.2.1'
gem "launchy"
end
$ bundle
$ rails g cucumber:install
$ rake cucumber
$ guard init cucumber
以下のGemを追加してbundle実行
# Yard
group :test, :development do
gem 'yard', :require => false
gem 'yard-cucumber', :require => false
gem 'redcarpet'
gem 'guard-yard'
gem 'yard-rails-plugin', :git => 'https://github.com/ogeidix/yard-rails-plugin.git', :tag => 'v0.0.1'
gem 'guard-ctags-bundler'
end
--charset UTF-8
"{lib,app,features}/**/*.{rb,feature}" --plugin yard-cucumber
$ guard init yard
$ guard
$ open http://localhost:8808
gem 'unicorn'
$ bundle
$ touch config/unicorn.rb
config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true
before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
Procfile
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
$ echo "RACK_ENV=development" >>.env
$ echo "PORT=3000" >> .env
$ echo ".env" >> .gitignore
$ gem install foreman
$ foreman start
$ heroku login
$ heroku create --addons heroku-postgresql
$ heroku keys:add
$ git push heroku master
### Herokuデーターベースマイグレーション
```bash
$ heroku run rake db:migrate
$ heroku run rake db:seed
$ heroku ps:scale web=1
$ heroku ps
$ heroku open
$ heroku apps:rename sukusuku-app
サイト確認 http://sukusuku-app.herokuapp.com/
Procfile
guard: bundle exec guard
_app/views/layouts/_navigation_links.html.erb_を編集
devise.ja.ymlを_config/locales_に保存する。
_app/views/devise/_以下のファイルを編集する。
-
ログイン画面
- app/views/devise/sessions/new.html.erb
- _app/views/devise/shard/links.erb
-
アカウント編集画面
- app/views/devise/registrations/edit.html.erb
-
管理者画面
- app/views/admin/base/index.html.erb
-
ユーザー画面
- app/views/admin/users/index.html.erb
- app/views/admin/users/edit.html.erb
_app/config/application.yml_を作成してトラッキングIDとトラッキングドメインを明記する
$ rails g figaro:install
application.yml
google_analytics_key: "UA-XXXXXXX-XX"
google_analytics_domain: "herokuapp.com"
事前にトラッキングIDをGoogleAnlyticsで設定しおく。
application.ymlはレポジトリ管理対象にはならないのでローカル環境のみで管理する。
_app/views/layouts/_footer.html.erb_に以下のコードを追加
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '<%= ENV["google_analytics_key"]%>', '<%= ENV["google_analytics_domain"]%>');
ga('send', 'pageview');
</script>
_app/assets/javascripts/analytics.js.coffee_を追加する
$(document).on 'page:change', ->
if window._gaq?
_gaq.push ['_trackPageview']
else if window.pageTracker?
pageTracker._trackPageview()
ここまでの作業をコミットした後Figaroでアプリケーションのキー情報をherokuの環境変数に登録。
$ rake figaro:heroku['sukusuku']
Herokuへデプロイ
$ RAILS_ENV=production rake assets:precompile
$ git add -a
$ git commit -m "assets compiled for Heroku"
$ git push -f heroku master
_Gemfile_に以下を追加
group :development do
gem 'annotate', '2.5.0'
end
アノテーション実行
$ bundle install
$ bundle exec annotate
※dbスキーマに変更がある度にbundle exec annotateする必要がある
https://codeclimate.com/にログインする。
ダッシュボード画面の_Add Open Source Repo_からレポジトリを追加する。
_Gemfile_に追加する。
gem "codeclimate-test-reporter", group: :test, require: nil
_spec/spec_helper_の先頭に以下のコードを追加する。
require "codeclimate-test-reporter"
CodeClimate::TestReporter.start
_.travis.yml_に以下のコードを追加する。repo_tokenはCodeclimate管理画面の_Settings_メニューのTest Coverageに明記されている。
addons:
code_climate:
repo_token: 1213....
更新を反映
$ bundle
$ git push origin master