# Override .find, .find\_by\_id, etc

**URL:** <https://www.ruby-forum.com/t/override-find-find-by-id-etc/180736>\
**Category:** Rails\
**Created:** [December 28, 2009, 9:54am UTC](https://www.ruby-forum.com/t/override-find-find-by-id-etc/180736 "2009-12-28T09:54:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ledowong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/fbc32d/32.png) [@ledowong](https://www.ruby-forum.com/u/ledowong)\
**Post date:** [December 28, 2009, 9:54am UTC](https://www.ruby-forum.com/t/override-find-find-by-id-etc/180736/1 "2009-12-28T09:54:25Z")

</div>

I read these:  
[http://www.ruby-forum.com/topic/185297#new](http://www.ruby-forum.com/topic/185297#new)  
[http://www.freezzo.com/2008/05/14/override-default-find-conditions-for-model/](http://www.freezzo.com/2008/05/14/override-default-find-conditions-for-model/)

it works, it override the .find perfectly, however it does not cover  
.find\_by\_id or other .find\_by\_XXX

Is there anyway to override all the find function of a modal? I want to  
set the default “select” for User modal, only return name and id, but  
not the password by default.

Thanks

---

<div class="post-metadata">

**Author:** ![ledowong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/fbc32d/32.png) [@ledowong](https://www.ruby-forum.com/u/ledowong)\
**Post date:** [December 28, 2009, 11:54am UTC](https://www.ruby-forum.com/t/override-find-find-by-id-etc/180736/2 "2009-12-28T11:54:17Z")

</div>

On Dec 28, 9:54 am, Leonardo W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I read these:[How to properly override ActiveRecord::Base.find - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/185297#newhttp://www.freezzo.com/2008/05/14/override-default-find-conditions-fo)…
> 
> it works, it override the .find perfectly, however it does not cover  
> .find\_by\_id or other .find\_by\_XXX
> 
> Is there anyway to override all the find function of a modal? I want to  
> set the default “select” for User modal, only return name and id, but  
> not the password by default.

default\_scope ?

The methods linked above should also work in recent versions of rails

- find\_by\_xxx used to call find\_every/find\_initial directly but now  
calls find.

Fred

> ## Thanks
> 
> Posted viahttp://www.ruby-forum.com/.

–

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 removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

---

<div class="post-metadata">

**Author:** ![ledowong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/fbc32d/32.png) [@ledowong](https://www.ruby-forum.com/u/ledowong)\
**Post date:** [December 28, 2009, 3:17pm UTC](https://www.ruby-forum.com/t/override-find-find-by-id-etc/180736/3 "2009-12-28T15:17:23Z")

</div>

Thanks! I am using a very old version rails… thats why it does not  
work…  
I tested on new version rails and it works, happy now =)

Leonardo

Frederick C. wrote:

> On Dec 28, 9:54ï¿½am, Leonardo W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I read these:[How to properly override ActiveRecord::Base.find - Rails - Ruby-Forum](http://www.ruby-forum.com/topic/185297#newhttp://www.freezzo.com/2008/05/14/override-default-find-conditions-fo)…
> > 
> > it works, it override the .find perfectly, however it does not cover  
> > .find\_by\_id or other .find\_by\_XXX
> > 
> > Is there anyway to override all the find function of a modal? I want to  
> > set the default “select” for User modal, only return name and id, but  
> > not the password by default.
> 
> default\_scope ?
> 
> The methods linked above should also work in recent versions of rails
> 
> - find\_by\_xxx used to call find\_every/find\_initial directly but now  
> calls find.
> 
> Fred
> 
> > ## Thanks
> > 
> > Posted viahttp://www.ruby-forum.com/.
> 
> –
> 
> 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 removed\_email\_address@domain.invalid.  
> To unsubscribe from this group, send email to  
> removed\_email\_address@domain.invalid.  
> For more options, visit this group at  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).
