Thanks everyone for all your suggestions. I'm using Ben's method as it works
best for my scenario, but I'll file away the techniques for future use.
My old rails doesn't have extract_options, so I broke this up into a few lines:
options = args.last.is_a?(Hash) ? args.last : {}
options = options.merge(:conditions=> ...
super(args.first, options)
--
Sonia Hamilton.
ben wiseley wrote:
> I think it really depends on what's needed. If you simply need to
> filter rows then, yes, the solution below is good. But, if you need
> custom logic for InnerCity vs Rural then I'd sub class the models like
> you originally suggested.
>
> Class Area < ActiveRecord::Base
> def taxes
> return .1
> end
>
> def calc_price(amount)
> amount + (amount * determine_taxes)
> end
> end
>
> class InnerCity < ActiveRecord:Base
> def self.find(*args)
> super(args.first,
> args.extract_options!.merge(:conditions=>{:postcode=>[2001, 2002]})
> end
>
> def taxes
> return .5 + new_bridge_tax
> end
>
> def calc_price(amount)
> amount + (amount * determine_taxes)
> end
> end
>
> etc.
>
>
> On Thu, Aug 13, 2009 at 6:27 PM, Dylan Egan <[email protected]
> <mailto:[email protected]>> wrote:
>
>
> It would go in the model.
>
> class Location < ActiveRecord::Base
> def self.all_from_inner_city
> find(:all, :conditions=>{:postcode=>[2001, 2002]})
> end
> end
>
> Location.all_from_inner_city
>
> or
>
> class Location < ActiveRecord::Base
> def self.from_inner_city(*args)
> find(args.first,
> (args.extract_options!.merge(:conditions=>{:postcode=>[2001, 2002]}))
> end
> end
>
> Location.from_inner_city(:all, :order => 'id DESC')
> Location.from_inner_city(:first)
>
> Cheers,
>
> Dylan.
>
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
or Rails Oceania" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rails-oceania?hl=en
-~----------~----~----~----~------~----~------~--~---