12. その他アプリの設定(pkun)
12.1. configディレクトリへ移動
# cd /var/www/app/pkun/config
12.2. キーを発行する
# bundle exec rake secret
【結果表示】
6**393************c036d8a5c0*ss557b***395911****614c9a4d176******28f0c
12.3. キー登録(「12.2キーの発行をしてから)
# export SECRET_KEY_BASE=`bundle exec rake secret`
※なにもしないと下記のエラーが表示される
■エラー発生
An unhandled lowlevel error occurred. The application logs may have details.
■参考URL
https://qiita.com/qiugits/items/7cd01f4b5cff4a31e053
http://blog.naichilab.com/entry/2015/12/05/232651
12.4. routesの設定
# vi /var/www/app/pkun/config/routes.rb
【編集内容】赤文字の箇所を追加する
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
resources :horses ※ここ追加
get "horses/index" ※ここ追加
end
12.5. SQLログの設定
# vi /var/www/app/pkun/config/environments/production.rb
【編集内容】赤文字の箇所を追加する
ActiveRecord::Base.logger = Logger.new("log/sql_#{Date.today}.log") ※ここ追加
ActiveRecord::Base.logger.level = 0 ※ここ追加
end
12.6. アプリディレクトリに移動
# cd /var/www/app/pkun
12.7. bootstrapの設定(scaffoldを適用)
# rails generate scaffold_controller Horse
# rails generate scaffold_controller Sex
# rails generate scaffold_controller Farm
【結果表示】
$ rails generate scaffold_controller Sex
create app/controllers/sexes_controller.rb
invoke erb
create app/views/sexes
create app/views/sexes/index.html.erb
create app/views/sexes/edit.html.erb
create app/views/sexes/show.html.erb
create app/views/sexes/new.html.erb
create app/views/sexes/_form.html.erb
invoke test_unit
create test/controllers/sexes_controller_test.rb
create test/system/sexes_test.rb
invoke helper
create app/helpers/sexes_helper.rb
invoke test_unit
invoke jbuilder
create app/views/sexes/index.json.jbuilder
create app/views/sexes/show.json.jbuilder
create app/views/sexes/_sex.json.jbuilder
$ rails generate scaffold_controller Farm
create app/controllers/farms_controller.rb
invoke erb
create app/views/farms
create app/views/farms/index.html.erb
create app/views/farms/edit.html.erb
create app/views/farms/show.html.erb
create app/views/farms/new.html.erb
create app/views/farms/_form.html.erb
invoke test_unit
create test/controllers/farms_controller_test.rb
create test/system/farms_test.rb
invoke helper
create app/helpers/farms_helper.rb
invoke test_unit
invoke jbuilder
create app/views/farms/index.json.jbuilder
create app/views/farms/show.json.jbuilder
create app/views/farms/_farm.json.jbuilder
12.8. bootstrapをインストールする
# rails g bootstrap:install
【結果表示】
$ rails g bootstrap:install
insert app/assets/javascripts/application.js
create app/assets/javascripts/bootstrap.js.coffee
create app/assets/stylesheets/bootstrap_and_overrides.css.less
create config/locales/en.bootstrap.yml
# rails g bootstrap:themed horses ※全てYを押す
■以下は全て「Y」を押下
Overwrite hogehogehoge? (enter "h" for help) [Ynaqdh] Y
【Yをおすところ】赤文字箇所
$ rails g bootstrap:themed horses
Overwrite /var/www/app/pkun/app/views/horses/index.html.erb?(enter "h" for help) [Ynaqdh] Y
force app/views/horses/index.html.erb
conflict app/views/horses/new.html.erb
Overwrite /var/www/app/pkun/app/views/horses/new.html.erb? (enter "h" for help) [Ynaqdh] Y
force app/views/horses/new.html.erb
conflict app/views/horses/edit.html.erb
Overwrite /var/www/app/pkun/app/views/horses/edit.html.erb? (enter "h" for help) [Ynaqdh] Y
force app/views/horses/edit.html.erb
conflict app/views/horses/_form.html.erb
Overwrite /var/www/app/pkun/app/views/horses/_form.html.erb? (enter "h" for help) [Ynaqdh] Y
force app/views/horses/_form.html.erb
conflict app/views/horses/show.html.erb
Overwrite /var/www/app/pkun/app/views/horses/show.html.erb? (enter "h" for help) [Ynaqdh] Y
force app/views/horses/show.html.erb
■参考URL
http://ruby-rails.hatenadiary.com/entry/20140801/1406818800
12.9. assets.compileの設定
※productionで起動した時に、画像が読み込まれないとかの対処
# vi /var/www/app/pkun/config/environments/production.rb
【編集内容】赤文字の箇所を修正(trueにする)
config.assets.compile = true
■参考URL
https://qiita.com/tomomomo1217/items/fa8dfa094cc4c0e4e350
12.10. assetファイルのコンパイル
※/app/assets以下のファイルをコンパイル
# RAILS_ENV=production bundle exec rake assets:precompile assets:clean