linuxの場合
sudo chkconfig --add nginx
sudo chkconfig nginx on
macの場合
cp /usr/local/Cellar/postgresql/9.5.0/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
railsで捉えたいexceptionの種類 library _builtin (Ruby 2.1.0)
raiseの仕方 https://docs.ruby-lang.org/ja/latest/doc/spec=2fcontrol.html#raise
エラーのgem GitHub - smartinez87/exception_notification: Exception Notifier Plugin for Rails
rescue_fromとすることでbeginとかしなくてもそのクラスで起きたエラーを拾ってくれる StandardErrorはちょっと色々広いすぎるので何ですが、、自分でエラーを定義したければlibとかで共通に作る
slack例
rescue_from StandardError do |exception| alert_exception(exception) end def perform(message, channel='dev') hook = Rails.configuration.x.send("slack_#{channel}") notifier = Slack::Notifier.new hook, http_options: { open_timeout: 2 } notifier.username = channel notifier.ping message end private def alert_exception(e) ExceptionNotifier.notify_exception(e) end
いろいろ頭の整理の為 application.rbに設定すると変更できる
①表示時のタイムゾーンをJSTに変更 config.time_zone = 'Tokyo'
②DB保存時のタイムゾーンをJSTに変更 config.active_record.default_timezone = :local
②を設定してなかった時
yesterday = Time.current - 1.days .where('hoges.hoge_finish_at >= ?', yesterday.strftime("%Y-%m-%d 00:00:00"))
DBがUTCなので画面と表示してる時間だと取れない
.where('hoges.hoge_finish_finish_at >= ?', yesterday.beginning_of_day)
でも以上のようにすると取れるようになった。railsで上手いこと変換してくれる? ちなみにutcに変換するには以下のようにする
yesterday.beginning_of_day.gmtime
まずslack側でwebhookの設定
https://creww.slack.com/apps/A0F7XDUAZ-incoming-webhooks
add configurationボタンを押して通知したいslack channel選択
gem 追加
gem 'slack-notifier'
slack側で取得したurlをhookに設定してtaskなどで以下を呼び出す
hook = "https://hooks.slack.com/services/XXXXXXXXXXXXXXXXX" if hook notifier = Slack::Notifier.new hook, http_options: { open_timeout: 2 } notifier.username = :dev begin notifier.ping "テストです。" rescue # no need report problem with Slack end else Rails.logger.warn 'Slack hook is missing' end
以上
実行bundle exec cap production deploy 01 $HOME/.rbenv/bin/rbenv exec bundle install --path /var/www/zen/shared/bundle --without development test --deployment --quiet 01 rbenv: bundle: command not found (Backtrace restricted to imported tasks) cap aborted! SSHKit::Runner::ExecuteError: Exception while executing as hoge@99.11.11.11: bundle exit status: 127 bundle stdout: Nothing written bundle stderr: rbenv: bundle: command not found SSHKit::Command::Failed: bundle exit status: 127 bundle stdout: Nothing written bundle stderr: rbenv: bundle: command not found Tasks: TOP => deploy:updated => bundler:install (See full trace by running task with --trace) The deploy has failed with an error: Exception while executing as hoge@99.11.11.11: bundle exit status: 127 bundle stdout: Nothing written bundle stderr: rbenv: bundle: command not found ** DEPLOY FAILED ** Refer to log/capistrano.log for details. Here are the last 20 lines:
rbenv exec gem install bundler
01:58 deploy:migrate [deploy:migrate] Run `rake db:migrate` 01:58 deploy:migrating 01 $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate 01 rake aborted! 01 PG::ConnectionBad: FATAL: Peer authentication failed for user "zen"
[hoge@ip-10-0-0-62 20161013121524]$ su - postgres パスワード: -bash-4.2$ psql postgres psql (9.2.18) Type "help" for help. postgres=# create user zen; CREATE ROLE postgres=# alter role zen createdb; ALTER ROLE postgres=# \du List of roles Role name | Attributes | Member of -----------+------------------------------------------------+----------- postgres | Superuser, Create role, Create DB, Replication | {} zen | Create DB postgres=# CREATE DATABASE hoge_production; CREATE DATABASE
まだエラーが出る
sudo find / -name "pg_hba.conf" /var/lib/pgsql9/data/pg_hba.conf sudo vim /var/lib/pgsql9/data/pg_hba.conf local を peerからmd5に変更 sudo /sbin/service postgresql restart 00:13 deploy:migrating 01 $HOME/.rbenv/bin/rbenv exec bundle exec rake db:migrate 01 rake aborted! 01 PG::ConnectionBad: fe_sendauth: no password supplied
sudo su postgres -c 'psql --username=postgres' ALTER USER postgres with encrypted password 'paasss'
local を peerからtrustに変更したら動いた、多分セキュリティ的にダメなんかなぁ
text formとボタンをくっつけて表示する方法
input-groupで囲ってそん中にinput-group-btn or input-group-addon入れりゃいいっぽい
.input-group = text_field_tag 'keyword', class: 'form-control input-lg search-input' %span.input-group-btn %button.btn.btn-primary.btn-search %i.fa.fa-search
上で画像を作る
app/views/shared/_head.html.hamlに書く
= favicon_link_tag '/favicon.ico
下記に配置
public/favicon.ico