# Dynamic Finders with \_or\_create Don't Work?

**URL:** <https://www.ruby-forum.com/t/dynamic-finders-with-or-create-dont-work/54874>\
**Category:** Rails\
**Created:** [March 14, 2006, 10:56pm UTC](https://www.ruby-forum.com/t/dynamic-finders-with-or-create-dont-work/54874 "2006-03-14T22:56:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dcian](https://www.ruby-forum.com/u/dcian)\
**Post date:** [March 14, 2006, 10:56pm UTC](https://www.ruby-forum.com/t/dynamic-finders-with-or-create-dont-work/54874/1 "2006-03-14T22:56:31Z")

</div>

What could cause this?

> > sdfl=PartNumber.find\_by\_part\_number(“1111111”)  
> > =\> #\<PartNumber:0xb78fc744 @attributes={“id”=\>“11601”,  
> > “part\_number”=\>“1111111”}\>
> 
> > sdfl=PartNumber.find\_or\_create\_by\_part\_number(“1111111”)  
> > NoMethodError: undefined method `find_or_create_by_part_number' for PartNumber:Class from /usr/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/base.rb:942:in`method\_missing’  
> > from (irb):5

I could swear this used to work.

- Ian

---

<div class="post-metadata">

**Author:** ![dcian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/91b2a8/32.png) [@dcian](https://www.ruby-forum.com/u/dcian)\
**Post date:** [March 16, 2006, 3:28pm UTC](https://www.ruby-forum.com/t/dynamic-finders-with-or-create-dont-work/54874/2 "2006-03-16T15:28:28Z")

</div>

Anyone? This is kinda disturbing to me. Am I the only person who has  
ever seen this? If the find\_by works, shouldn’t the find\_or\_create\_by  
also at least try to work? My setup is plain vanilla. PartNumber only  
has one attribute, part\_number besides the id.

Ian H. wrote:

> What could cause this?
> 
> > > sdfl=PartNumber.find\_by\_part\_number(“1111111”)  
> > > =\> #\<PartNumber:0xb78fc744 @attributes={“id”=\>“11601”,  
> > > “part\_number”=\>“1111111”}\>
> > 
> > > sdfl=PartNumber.find\_or\_create\_by\_part\_number(“1111111”)  
> > > NoMethodError: undefined method `find_or_create_by_part_number' for PartNumber:Class from /usr/lib/ruby/gems/1.8/gems/activerecord-1.12.2/lib/active_record/base.rb:942:in`method\_missing’  
> > > from (irb):5
> 
> I could swear this used to work.
> 
> - Ian
