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]> 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
-~----------~----~----~----~------~----~------~--~---