What is the best solution for applying a default condition to a model,
for example only records where active is boolean true? My initial
implementation overrode the find method using with_scope to apply the
condition, but I soon discovered that didn't work with the
will_paginate plugin.
I currently have a named_scope called :active that applies the
conditions, but I'm not sure how to incorporate that so that it is
always applied to find and find_by_* without having to use it inside
of the controller.
I'd also like to apply a default sort order and have this code. Could
I follow similar logic for applying the condition?
def self.find(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
if not options.include? :order
options[:order] = 'created_at desc'
end
args.push(options)
super
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" 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/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---