Forum: Ruby on Rails Extend the find-method: more conditions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Helmut Sedding (Guest)
on 2005-12-26 20:04
(Received via mailing list)
Hi,

I want to share some helpful code snippet. Can it further be optimized?
Or is this even good to do?

Put this in your model to write a customized find method having more
conditions:

   def self.find_active(*args)
     options = extract_options_from_args!(args)
     conditions = "AND (#{sanitize_sql(options[:conditions])})" if
options[:conditions]
     options[:conditions] = "ADDITIONAL_CONDITIONS_GO_HERE
#{conditions}"
     args << options
     find(*args)
   end

regards,
Helmut
This topic is locked and can not be replied to.