タグ

ブックマーク / fg-180.katamayu.net (2)

  • 83's : Rails

    t.referencesで外部キーの定義をちょっと簡単に、しかし明確に書ける February 21, 2008 23:00 Permalink Comments (137) Trackbacks (0) Rails, ActiveRecord なんでかこういうちょっと気の利いたやつは知るとうれしくなってしまう。 マイグレーションでt.integer :tag_idと書くところをt.references :tagと書けるんだってさ。 確かに関連に使うフィールドはintのxxx_idって規約で決まってんだから、いちいちそんなこと書きたくないよね。 「referencesってintegerより長くなって指が絡まりそうだYO!」と言いたくなる衝動は :polymorphic => trueあたりを見てなだめていただきたい。DRY優先。 詳しくは以下。 TableDefinition#refere

    kakuhen1rfeverheiten
    kakuhen1rfeverheiten 2009/08/18
    helper から controller のメソッドを呼び出す
  • 83's : helper_method

    メモメモ。 コントローラで class FooController < ActionController::Base def foo ... end helper_method :foo end とやるとビューの中でfooが使える。 controller.fooを呼んでくれるぽい。 ちょっと幸せになれる。 helper_attrなんてのもある。 # Declare a controller attribute as a helper. For example, # helper_attr :name # attr_accessor :name # makes the name and name= controller methods available in the view. # The is a convenience wrapper for helper_method. Trackb

  • 1