# Rails 2.0 missing find\_or\_create\_by\_name and find\_or\_initialize\_by\_name

**URL:** <https://www.ruby-forum.com/t/rails-2-0-missing-find-or-create-by-name-and-find-or-initialize-by-name/117740>\
**Category:** Rails\
**Created:** [October 19, 2007, 8:49pm UTC](https://www.ruby-forum.com/t/rails-2-0-missing-find-or-create-by-name-and-find-or-initialize-by-name/117740 "2007-10-19T20:49:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/96bed5/32.png) [@Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/u/Jesper_RSSSSnn-Jens)\
**Post date:** [October 19, 2007, 8:49pm UTC](https://www.ruby-forum.com/t/rails-2-0-missing-find-or-create-by-name-and-find-or-initialize-by-name/117740/1 "2007-10-19T20:49:36Z")

</div>

Hey.

just found out that Rails 2.0 (in the prerelease version) does not  
have the extended dynamic finders  
find\_or\_create\_by\_name and find\_or\_initialize\_by\_name

They are mentioned in the old 1.x docs

> **[ActiveRecord::Base](https://api.rubyonrails.org/classes/ActiveRecord/Base.html)**
>
> Active Record Active Record objects don't specify their attributes directly, but rather infer them from the table definition with which they're linked.

(section “Dynamic attribute-based finders”)

But I couldnt find it in the edge docs ([http://caboo.se/doc.html](http://caboo.se/doc.html))

Could somebody hint me at what to do? Did they move to a plugin?  
which? Are there lines I can implement myself?

Any help appreciated,

Thanks!

/Jesper

---

<div class="post-metadata">

**Author:** ![Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/96bed5/32.png) [@Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/u/Jesper_RSSSSnn-Jens)\
**Post date:** [October 19, 2007, 9:04pm UTC](https://www.ruby-forum.com/t/rails-2-0-missing-find-or-create-by-name-and-find-or-initialize-by-name/117740/2 "2007-10-19T21:04:49Z")

</div>

They’re still there. Check out method\_missing on ActiveRecord::Base. 🙂

RSL

---

<div class="post-metadata">

**Author:** ![Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/96bed5/32.png) [@Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/u/Jesper_RSSSSnn-Jens)\
**Post date:** [October 19, 2007, 10:30pm UTC](https://www.ruby-forum.com/t/rails-2-0-missing-find-or-create-by-name-and-find-or-initialize-by-name/117740/3 "2007-10-19T22:30:49Z")

</div>

Thx Russel.  
But how come that it does not work. I get this error printed below.  
What can I do to make it work with the current pre-release?

/Jesper

=========

> > PoliceJournal.find\_or\_initialize\_by\_name(“hello”)  
> > NoMethodError: undefined method `find_or_initialize_by_name' for #<Class:0x48fc90c> from C:/Documents and Settings/Administrator/My Documents/ rails/project/vendor/rails/activerecord/lib/active_recor d/base.rb:1277:in`method\_missing’  
> > from (irb):1

---

<div class="post-metadata">

**Author:** ![Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/96bed5/32.png) [@Jesper\_RSSSSnn-Jens](https://www.ruby-forum.com/u/Jesper_RSSSSnn-Jens)\
**Post date:** [October 19, 2007, 11:04pm UTC](https://www.ruby-forum.com/t/rails-2-0-missing-find-or-create-by-name-and-find-or-initialize-by-name/117740/4 "2007-10-19T23:04:11Z")

</div>

DOH.  
Sorry. found out that my model PoliceJournal did not have “name” I  
should have used  
PoliceJournal.find\_or\_initialize\_by\_number

DOH.  
Sorry to have interrupted you.
