- saveメソッドは、保存できない場合falseを返します。
save!メソッドは、保存できない場合例外ActiveRecord::RecordInvalidが発生します。
カラム名_changed?でそのカラムが変更されたか分かります。
model.changes {“report”=>[“こんばんわ報告”, “こんばんわ報告更新するよ\r\nどうすんの”]} 変更前と変更後の値が出る
save(:validation => false)はバリデーションをスキップ
.build や build_xxx buildを使うと親モデルに対する外部参照キーを自動でセットできるらしい
オブジェクト指向について
mailcatcherが起動しない
起動しないと思ったらただrehashしたら直った、、、、
[git][* fix-iroiro]:~/rails_projects/log/ mailcatcher zsh: command not found: mailcatcher [git][* fix-iroiro]:~/rails_projects/log/ rbenv rehash [git][* fix-iroiro]:~/rails_projects/log/ mailcatcher
tooltipでマウスオーバ表示する
titleに表示したいもんを入れればいいっぽ
- readers = set_read_history_contents(reads) %a{href: 'javascript:void(0);', title: "#{readers}", data: {toggle: "tooltip", placement: "top", html: "true"}} #{read_desc}
helperでtitleに入れるもんを設定してみる
def set_read_history_contents(reads) reads.map do |r| content_tag(:div, class:'clearfix') do concat ([content_tag(:small, r.user.name, class:'pull-left'), content_tag(:small, r.read_at.strftime(t('date.formats.long')), class:'pull-right') ].join.html_safe ) end end.join.html_safe end
よくあるgem libv8とtherubyracerのインストールでエラーになるやつ
An error occurred while installing libv8 (3.16.14.7), and Bundler cannot continue.
libv8はjavascript v8の何からしい
bundle config build.libv8 --with-system-v8
こうするとlibv8はインストールできるがtherubyracerでエラー
An error occurred while installing therubyracer (0.12.2), and Bundler cannot continue.
~/.bundle/configの以下を消して
UNDLE_BUILD__NOKOGIRI: "--use-system-libraries" BUNDLE_BUILD__LIBV8: "--with-system-v8"
bundle update libv8
動いたね
bootstarap ファイル選択のデザインを変える
bootstarap ファイル選択を少し変えたい時
- 以下は枠線をなくしたい場合だけ
form { .form-control[type="file"] { border: 0px; box-shadow: none; padding-left: 0; } }
もっと変えたければ↓
window.onloadと$(document).readyの違い
- window.onload onloadイベント発生時に実行されますが、 これはDOMツリーの構築だけでなく、画像や他の全てのデータの 読み込みが完了した時 1つしか実行されない
window.onload = ()-> $('.js-bootstrap-switch').bootstrapSwitch()
- $(document).ready こちらは画像の読み込みなどは待たず、 DOMツリーの構築が終わった時点で実行されます。window.onloadで指定されているものよりも先に実行されます。
$(document).ready(function(){ console.log('ready 1'); });