xiaoniu’s blog

主なエンジニア技術、勉強の話

RailsのActiveRecordに使ったjoinsとRubyの配列join

  • Rubyの配列にjoinメソッドの使い方

    配列の要素の間に文字列を挟んで連結し、文字列を返す

    [a,b,c].join("-")   #=>"a-b-c"
  • RailsのModelにjoinsメソッドの使い方

    Railsのモデルに使ったjoinsはモデルとテーブルが内部結合(INNER JOIN)して結合先のリストを取得する

     User.joins(:children)  #=> childrenがあるUserたちだけ取得する

    SQL文は以下のようになります

    SELECT u.* FROM users u
    INNER JOIN children c
      ON u.id = c.user_id 
    

MACで新しいRORプロジェクト作成するメモ

Bashをクリアする

command + k 

インストールしたGemリストはき出す

gem query --local
OR
gem list --local

Gemインストールした時、毎回'sudo'を入力しないと、インストールできない問題解消

echo 'export GEM_HOME=$HOME/gems' >> ~/.bash_profile
echo 'export PATH=$HOME/gems/bin:$PATH' >> ~/.bash_profile

From Great Expectations

感動された箇所①

At the scene when pip left the village where he was grown up.

Heaven knows we need never be ashamed of our tears, for they are rain upon the blinding dust of earth, overlaying our hard hearts.

 At the scene that before pip leave the village, he took a walk with Biddy

 read these sentences make me thought my mom. she always give priority to every family members  .

We talked a good deal as we walked, and all that Biddy said seemed right.Biddy was never insulting, or capricious, or Biddy today adn somebody else tomorrow; she would have derived only pain, and no pleasure, from giving me pain, she would far rather have wounded her own breast than mine. 

 

Rails.configuration.xは何

config配下に設定したコードは下記の方法より呼び出しできます

config/setting.yml
   ap_name : "Test app"
   ap_info: [
     description : "owner_info",
     creator  : "ABC"
 ]
  • ネストの場合(ap_info)

Rails.configuration.x.setting」によりアクセスできます。

    Rails.configuration.x.setting.ap_info.description #=>owner_info
    Rails.configuration.x.setting.ap_info.creator #=>ABC
  • 単一の場合

    「Rails.configuration.setting」によりアクセスできます。

     Rails.configuration.setting.ap_name    # =>Test app

 

 

 

 

crontabコマンド

定期的にジョブ実行のスケジュールを設定するcronを設定できる

crontab -l

設定しているcronを表示する

crontab -e

cronを設定する、cron設定する時、実行時間は分、時、日、月、曜日の順指定する

crontab -r

cronを削除する