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
Contents rssrss
光ファイバーを二次元振動させて走査するAR用ディスプレイ
因果の取り違え
Swift2's defer for CoffeeScript
mongodb-3.0からcreateIndexのdropDupsが無くなったらしい
mongodb-3.0以降のWiredTigerの設定を動的に変更する方法
一般楕円の高速生成アルゴリズムへの道標
farro mantecatoのレシピ
Droonga関連の記事のまとめ
RuntimeErrorの特定のメッセージに限定してrescueする方法
jQueryでscriptタグを実行せずにappendする
Tags
coffeescriptdefergroongajsmemonodenodejs
Comments rssrss
http://rlu.ru/5cfBn http://rlu.ru/5cfBn: Greetings auto enthusiasts, gotta share а amazing ... 05/16 18:38
https://xn--9m1bj7w5fr3e8te72a7k351ewff.kr/bbs/board.php?bo_table=free&wr_id=201227 https://xn--9m1bj7w5fr3e8te72a7k351ewff.kr/bbs/board.php?bo_table=free&wr_id=201227: Unlock Singapore's shoppng secrets at Kaizenaire.ⅽ... 05/16 17:50
https://alexander-tech.org/ https://alexander-tech.org/: I need to to thank you for this excellent read!! ... 05/16 11:56
https://unosport.pl/ https://unosport.pl/: Hmm is anyone else experiencing problems with the ... 05/16 10:37
https://strategyreviewer.com/ https://strategyreviewer.com/: Marvelous, what a web site it is! This blog presen... 05/16 10:01
https://listji.com/index.php?page=user&action=pub_profile&id=72479&item_type=active&per_page=16 https://listji.com/index.php?page=user&action=pub_profile&id=72479&item_type=active&per_page=16: As tһe premier furniture store аnd comprehensive f... 05/16 07:16
https://khvanchkaravino.ru https://khvanchkaravino.ru: Квартира мечты за 2 месяца — помогаем выбрать мебе... 05/16 05:06
https://www.tequilagames.com https://www.tequilagames.com: Thanks for finally writing about >something new an... 05/16 03:16