Last active
February 27, 2017 09:25
-
-
Save tigawa/304a55b5895c81c2a9e0 to your computer and use it in GitHub Desktop.
rails ベストプラクティス heroku,bootstrap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. rails new project | |
rails new test-app --database=postgresql --skip-test-unit --skip-bundle | |
# 2. .ignoreファイルの編集 | |
gibo OSX Ruby Rails Sass SublimeText > .gitignore | |
#.gitignoreから以下のファイルを削除する。 | |
/config/initializers/secret_token.rb | |
#secret_token.rbの編集 ※Herokuはアプリケーション名 application.rbにアプリケーション名が記載されている。 | |
/config/initializers/secret_token.rb | |
test-app::Application.config.secret_key_base = ENV['SECRET_KEY_BASE'] || 'sometoken' | |
# 3. Gemfileの編集 | |
# therubyracerをコメントアウト | |
# ▼▼▼ ここから追加 | |
# twitter bootstrap css & javascript toolkit | |
gem 'twitter-bootswatch-rails', '~> 3.2.0' | |
# twitter bootstrap helpers gem, e.g., alerts etc... | |
gem 'twitter-bootswatch-rails-helpers' | |
# turbolinks support | |
gem 'jquery-turbolinks' | |
gem 'nokogiri', '~> 1.6.1' | |
gem 'rails-i18n', '~> 4.0.1' | |
group :test do | |
gem 'rspec-rails', '~> 3.0.0.beta2' | |
gem 'spring-commands-rspec', '~> 1.0.1' | |
gem 'capybara', '~> 2.2.1' | |
gem 'factory_girl_rails', '~> 4.4.1' | |
gem 'database_cleaner', '~> 1.2.0' | |
end | |
group :production, :staging do | |
# ログ保存先変更、静的アセット Heroku 向けに調整 | |
gem 'rails_12factor' | |
end | |
# ▲▲▲ ここまで | |
echo gem: --no-rdoc --no-ri > ~/.gemrc | |
bundle install | |
# 4. config/application.rb編集 | |
# ▼▼▼ ここから追加 | |
# Set timezone | |
config.time_zone = 'Tokyo' | |
config.active_record.default_timezone = :local | |
# 日本語化 | |
I18n.enforce_available_locales = true | |
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s] | |
config.i18n.default_locale = :ja | |
# generatorの設定 | |
config.generators do |g| | |
g.orm :active_record | |
g.template_engine :erb | |
g.test_framework :rspec, :fixture => true | |
g.fixture_replacement :factory_girl, :dir => "spec/factories" | |
g.view_specs false | |
g.controller_specs false | |
g.routing_specs false | |
g.helper_specs false | |
g.request_specs false | |
g.assets false | |
g.helper false | |
end | |
# libファイルの自動読み込み | |
config.autoload_paths += %W(#{config.root}/lib) | |
config.autoload_paths += Dir["#{config.root}/lib/**/"] | |
# ▲▲▲ ここまで | |
#5. 日本語化ファイルの取得 | |
wget https://raw.github.com/svenfuchs/rails-i18n/master/rails/locale/ja.yml -P config/locales/ | |
#6. application.jsに以下を追加してturbolinksで$(document).ready()のイベントが発火するように修正 | |
//= require jquery.turbolinks | |
#7 欠番 | |
#8 spring準備 | |
bin/bundle binstubs spring | |
bin/spring binstub --all | |
#9 rspecコマンドのインストール | |
bin/spring binstub rspec | |
#10 RSpecのひな形の作成 | |
bin/rails g rspec:install | |
echo '--color --drb -f d' > .rspec | |
# database.ymlのdevelopment:,test:に以下を追加 | |
host: localhost(dockerの場合は、dockerのIPアドレス(動的にIPをとってこれないか)) | |
username: board(アプリケーション名) | |
password: board | |
# postgresにuserを作成 | |
docker exec -it postgre /bin/bash | |
su - postgres | |
createuser -a -d -U postgres -P board | |
#11 developmentのDBの作成。(testも一緒に作成されます) | |
bin/rake RAILS_ENV=development db:create | |
# データベースの確認 | |
psql -h $(boot2docker ip) -U postgres | |
¥l | |
#12 bootstrapテーマ適用 | |
#テーマを選択 | |
#http://bootswatch.com/ | |
# "darkly"がテーマ | |
bin/rails g bootswatch:install darkly | |
bin/rails g bootswatch:import darkly | |
bin/rails g bootswatch:layout darkly | |
#13 aplication.cssを編集 | |
# 以下を追加 darkly.cssをimport | |
*= require darkly | |
#14 aplication.jsを編集 | |
# 以下を追加 darkly.jsをimport | |
//= require darkly | |
#15 application_controller.rbの編集 | |
layout 'darkly' | |
layoutのbodyを次のように修正する。 | |
<body style="padding-top: 50px"> | |
#16 config/initializers/assets.rb の追加 | |
Rails.application.config.assets.precompile += %w(darkly.js darkly.css) | |
# サーバを起動 | |
bin/rails s | |
#17 heroku login | |
heroku login | |
# heroku アプリ登録 | |
heroku create test-app | |
#18 secret_tokenを生成 | |
heroku config:set SECRET_KEY_BASE=`rake secret` | |
#19 HerokuのタイムゾーンをTokyoに設定 | |
heroku config:add TZ=Asia/Tokyo | |
#21 heroku ディプロイ | |
git add . -A | |
git commit -m "add scaffold" | |
git push heroku master | |
heroku run rake db:migrate | |
### heroku おまけ ### | |
# ブラウザ起動 | |
heroku open | |
# ログをtails | |
heroku logs -t | |
# herokuへssh接続 | |
heroku run bash | |
# DBの作り直し | |
heroku rake db:migrate:redo STEP=10 | |
# newrelic 設定 | |
http://jangajan.com/blog/2014/10/20/use-new-relic-in-rails4-at-heroku/ | |
http://qiita.com/edvakf@github/items/3f40f476968bbcfc126d ← 監視設定はここに書いてある | |
# newrelic 起動 | |
heroku addons:open newrelic | |
### rails おまけ ### | |
# scaffold | |
bin/rails g scaffold product name price:integer | |
# config/routes.rb 編集 | |
root :to => 'products#index' | |
# migrate | |
bin/rake RAILS_ENV=development db:migrate | |
# <モデル名(複数名)> -f # 該当のモデルのビューのスタイルを変更する -fは強制 | |
bin/rails g bootswatch:themed products -f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment