The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Shorthand named scopes

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Duncan Beevers

Posts: 68
Nickname: dbeevers
Registered: May, 2008

Duncan Beevers is a hack and jester building shiny baubles from bytes and tears.
Shorthand named scopes Posted: May 10, 2008 9:21 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Duncan Beevers.
Original Post: Shorthand named scopes
Feed Title: dweebd
Feed URL: http://www.dweebd.com/feed/
Feed Description: Ruby ejecta from the leading edge
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Duncan Beevers
Latest Posts From dweebd

Advertisement
In the old days, we did this: User.find(:all, :conditions => { :subscribed => true }, :order => 'created_at DESC' ) And then this: User.find_all_by_subscribed(true, :order => 'created_at DESC' ) How about this? User.for_subscribed(true).order_by('created_at DESC').find(:all) Here’s the how! class User < ActiveRecord::Base named_scope_for :subscribed end Whup-cha! class ActiveRecord::Base def self.named_scope_for attribute named_scope "for_#{attribute}", lambda { |attribute_value| [...]

Read: Shorthand named scopes

Topic: Ruby In Steel Personal - FREE with PC Pro Previous Topic   Next Topic Topic: Ruby Hoedown 2008

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use