# Extending find() in a horrible way

**URL:** <https://www.ruby-forum.com/t/extending-find-in-a-horrible-way/75896>\
**Category:** Rails\
**Created:** [November 14, 2006, 2:15am UTC](https://www.ruby-forum.com/t/extending-find-in-a-horrible-way/75896 "2006-11-14T02:15:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![henster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a183cd/32.png) [@henster](https://www.ruby-forum.com/u/henster)\
**Post date:** [November 14, 2006, 2:15am UTC](https://www.ruby-forum.com/t/extending-find-in-a-horrible-way/75896/1 "2006-11-14T02:15:24Z")

</div>

Hi all,

I’m trying to add a default scope to all calls to find.

My method is really ugly and wondered if anyone had a better solution?  
It also doesn’t effect all the dynamic finder methods.

(I’ve posted this a couple of times but I’m not seeing it in google  
groups… not sure if this will work.)

cheers  
-h

class LinkCategory \< ActiveRecord::Base

def self.find(\*args)  
options = args.last.is\_a?(Hash) ? args.pop : {}  
sql = “site\_id=’#{some\_integer}’”  
if options[:conditions] && !options[:conditions].empty?  
options[:conditions] += " AND #{sql}"  
else  
options[:conditions] = “#{sql}”  
end  
args \<\< options  
super(\*args)  
end

end

---

<div class="post-metadata">

**Author:** ![henster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a183cd/32.png) [@henster](https://www.ruby-forum.com/u/henster)\
**Post date:** [November 14, 2006, 5:12am UTC](https://www.ruby-forum.com/t/extending-find-in-a-horrible-way/75896/2 "2006-11-14T05:12:12Z")

</div>

honestly I have no dang idea what thats suppose to do how about some  
documentation?

---

<div class="post-metadata">

**Author:** ![henster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a183cd/32.png) [@henster](https://www.ruby-forum.com/u/henster)\
**Post date:** [November 14, 2006, 8:05am UTC](https://www.ruby-forum.com/t/extending-find-in-a-horrible-way/75896/3 "2006-11-14T08:05:46Z")

</div>

Try this:

[http://roman2k.free.fr/rails/meantime\_filter/0.1.2/](http://roman2k.free.fr/rails/meantime_filter/0.1.2/)

it is exactly what you need.

pt.

On 11/13/06, Henry T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> else  
> options[:conditions] = “#{sql}”  
> end  
> args \<\< options  
> super(\*args)  
> end
> 
> end
> 
> >

–  
Parker T.

> **[ParkErt.com is for sale | HugeDomains](https://www.hugedomains.com/domain_profile.cfm?d=parkert.com)**
>
> Join thousands of people who own a premium domain. Affordable financing available.

510.541.0125

---

<div class="post-metadata">

**Author:** ![henster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a183cd/32.png) [@henster](https://www.ruby-forum.com/u/henster)\
**Post date:** [November 14, 2006, 3:16pm UTC](https://www.ruby-forum.com/t/extending-find-in-a-horrible-way/75896/4 "2006-11-14T15:16:38Z")

</div>

Wow, thanks for the link… My favourite plugin so far…

cheers  
-henry
