iPhoneやiPodTouchでホームのボタンに登録する時に利用される、
AppleTouchIconとして、登録された画像を利用できるようにしました。

iPhone/iPodTouchをお持ちの方は、ぜひお試しください。

posted by genki genki on Fri 1 Aug 2008 at 22:16 with 0 comments

named_scopeは大変素晴らしいRailsの新しい機能ですが、
おなじみのwith_scopeのように、
スコープつきのブロックを伴った利用ができないという問題がありました。
例えばこんな感じに利用しようとしてもうまくいきません。

ruby>>
User.active do
User.count # => Not run
end

User.active.with_scope do
User.count #=> Not scoped
end
<<ruby

そこで、昔ながらのwith_scopeと同じようにnamed_scopeを使えるようにする
Gemプラグインを作りました。

with_named_scope

これを使うと、以下のように期待通りに動きます。

ruby>>
User.active.with do
User.count #=> User.active.count
end
<<--

なかなか便利だと思うので、Rails本家にパッチを送っておきました。

Improved named_scope to be used like as with_scope

posted by genki genki on Fri 1 Aug 2008 at 21:09 with 0 comments

以下の記事は、調査の結果現状のRuby on Rails
では期待通りに動かないことがわかりました。


Rails-2.1の新機能であるnamed_scopeを使うと、従来のwith_scope
では綺麗にかけなかったスコープの選択を簡潔に記述することができます。

rails>>
def gadgets_on_sidebar(place = 'index')
case place.to_s
when 'index'; Gadget.on_index
when 'show'; Gadget.on_show
else Gadget.all
end.with_scope{active_gadgets + Gadget.mandatories}
end
<<--

各スコープメソッドは、ActiveRecord::NamedScope::Scope
オブジェクトを返すので、
これを条件にしたがって選択し、最後に.with_scope
を呼んでスコープを適用します。


そこで、
with_named_scope
というGemプラグインをつくり、
上述のように処理できるようにしました。
以下のようになります。

rails>>
def gadgets_on_sidebar(place = 'index')
case place.to_s
when 'index'; Gadget.on_index
when 'show'; Gadget.on_show
else Gadget.all
end.with{active_gadgets + Gadget.mandatories}
end
<<--

ということで、Rails本家にもpatchを送っておきました。

posted by genki genki on Fri 1 Aug 2008 at 16:06 with 3 comments