諸行無常

IT色々お勉強中のブログ

オブジェクト指向について

オブジェクト指向で書く理由、それは変更に対して柔軟に対応するため

  • ポリモーフィズムとは

    • ざっくりいえば引数を受け取ったインスタンスがクラスによって違う振る舞いをする
    • 共通のメソッドを呼び出すが、オブジェクトによってその機能を変化させる
    • 同じメソッドなのに、返ってくる答えの種類がちがう
  • カプセル化とは

    • カプセル化とは複雑な部分を隠し、無駄な操作をしなくても良い状態にそのものを洗練させ、分かりやすい状態にするということ
    • そのものにまだ名前が付いていない時は、それに正しい名前をつけるということが、カプセル化の最後の仕上げ
    • 他のクラスの干渉をうけなくなり、その影響で変数を他のクラスから変更できなくなる
  • 継承とは

tooltipでマウスオーバ表示する

titleに表示したいもんを入れればいいっぽ

getbootstrap.com

- 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

動いたね

d.hatena.ne.jp

bootstarap ファイル選択のデザインを変える

bootstarap ファイル選択を少し変えたい時

  • 以下は枠線をなくしたい場合だけ
form { 
 .form-control[type="file"] {
    border: 0px;
    box-shadow: none;
    padding-left: 0;
  }
}

もっと変えたければ↓

Bootstrapのfileアップロードフォームがダサいから装飾してみた | vdeep

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');
});

rails db index名長すぎて怒られる

  • index名長すぎて怒れれたので以下のようにnameを指定してみる
  def change
    create_table :pogehoge_members_permissions do |t|
      t.references :pogehoge_member, index: true, foreign_key: true
      t.references :pogehoge_member_permission, index: true, name: 'index_om_permissions_on_om_permission_id', foreign_key: true

      t.timestamps null: false
    end
  end
  • んっ、まだ怒られる↓
ArgumentError: Index name 'index_pogehoge_members_permissions_on_pogehoge_member_permission_id' on table 'pogehoge_members_permissions' is too long; the limit is 63 characters
  • hashに入れて指定したら怒られないのね、、
  def change
    create_table :pogehoge_members_permissions do |t|
      t.references :pogehoge_member, index: true, foreign_key: true
      t.references :pogehoge_member_permission, index: { name: 'index_om_permissions_on_om_permission_id' }, foreign_key: true

      t.timestamps null: false
    end
  end

rails/schema_definitions.rb at 4-2-stable · rails/rails · GitHub