ミームの死骸を待ちながら

We are built as gene machines and cultured as meme machines, but we have the power to turn against our creators. We, alone on earth, can rebel against the tyranny of the selfish replicators. - Richard Dawkins "Selfish Gene"

We are built as gene machines and cultured as meme machines, but we have the power to turn against our creators.
We, alone on earth, can rebel against the tyranny of the selfish replicators.
- Richard Dawkins "Selfish Gene"

雑メモ

ControllerとView

コントローラ中には、index, list, showなどのメソッドが定義されている。メソッドが有効なURLになっている。メソッド内で定義されたインスタンス変数がビューの中で利用される。インスタンスじゃないと透過しない。テーブルの内容を取り出して変数に格納しておくケース多し。

ActiveRecord

division = Division.find(:first, :include => :groups )

のようにSQL文の代わりになる。

テーブル名は複数形

generateを利用したときに、 モデル名としてProductを指定した場合、テーブル名は大文字が小文字になり、 複数形に変化。products。
validationサニタイズだけではなく、例えば数値の入力を期待しているとことには数値が、文字列であれば文字列であることをアプリケーションでチェック、問題があればはじく。価格は0以上の整数である必要。モデルに次の記述を追加し、整数であることのチェック。

validates_numericality_of :price, :only_integer => true

仲間としてvalidates_presence_of、validates_uniquness_ofなど。View側で<%=h %>使えばHTMLタグのサニタイジング。ただしhはメソッドである点注意。

<td colspan=2>横連結</td><td rowspan=2>縦連結</td>