# Naming Error: "uninitialized constant ActionRecord"

**URL:** <https://www.ruby-forum.com/t/naming-error-uninitialized-constant-actionrecord/132660>\
**Category:** Rails\
**Created:** [March 22, 2008, 8:14pm UTC](https://www.ruby-forum.com/t/naming-error-uninitialized-constant-actionrecord/132660 "2008-03-22T20:14:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ocelotspot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ecccb3/32.png) [@ocelotspot](https://www.ruby-forum.com/u/ocelotspot)\
**Post date:** [March 22, 2008, 8:14pm UTC](https://www.ruby-forum.com/t/naming-error-uninitialized-constant-actionrecord/132660/1 "2008-03-22T20:14:06Z")

</div>

I’m using Rails 2.0.2 with Ruby 1.8.6 on Mac OSX Leopard. I’m trying to  
follow the instructions in “Ruby for Rails” by David A. Black but I’m  
getting an error when I attempt to display one of the views. I know the  
book was written for Rails 1.X and I’m assuming that’s where the problem  
is.

For my methods I have:

class Composer \< ActiveRecord::Base  
has\_many :works  
end

class Work \< ActionRecord::Base  
belongs\_to :composer  
has\_many :editions  
end

For my composer controller I have:  
class ComposerController \< ApplicationController  
def show  
@composer = Composer.find(params[:id])  
end  
end

Then in the view I’m having problems with this line:  
\<% @composer.works.each do |w| %\>

Here’s the actual error:  
NameError in Composer#show

Showing composer/show.html.erb where line #5 raised:

uninitialized constant ActionRecord

Extracted source (around line #5):

2: “Works by #{@composer.first\_name} #{@composer.last\_name}” %\>  
3:

Click on any work to see all available editions of that work.

  
4: 
  
5: \<% @composer.works.each do |w| %\>  
6: - \<%= link\_to w.title,  
7: :controller =\> “work”,  
8: :action =\> “show”,

I think it’s having a problem with me calling “works” on  
Composer.find(params[:id]) but since work belongs\_to composer and  
composer has\_many works, I don’t know what the naming error is. Do I  
have to specify a foreign\_key in the method to “works”? If so, what  
would the default be if not “works”.

---

<div class="post-metadata">

**Author:** ![ocelotspot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ecccb3/32.png) [@ocelotspot](https://www.ruby-forum.com/u/ocelotspot)\
**Post date:** [March 22, 2008, 8:40pm UTC](https://www.ruby-forum.com/t/naming-error-uninitialized-constant-actionrecord/132660/2 "2008-03-22T20:40:55Z")

</div>

Hi –

On Sat, 22 Mar 2008, Kelly T. wrote:

> has\_many :works  
> Showing composer/show.html.erb where line #5 raised:
> 
> uninitialized constant ActionRecord

My fault. It says ActionRecord in the book; it should be ActiveRecord.  
Not my finest hour, apparently. But hang in there – there’s some  
really good stuff in that book 🙂

David

–  
Upcoming Rails training from David A. Black and Ruby Power and Light:  
ADVANCING WITH RAILS April 14-17 New York City  
INTRO TO RAILS June 9-12 Berlin  
ADVANCING WITH RAILS June 16-19 Berlin  
CORE RAILS June 24-27 London (Skills Matter)  
See [http://www.rubypal.com](http://www.rubypal.com) for more info!

---

<div class="post-metadata">

**Author:** ![ocelotspot](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/ecccb3/32.png) [@ocelotspot](https://www.ruby-forum.com/u/ocelotspot)\
**Post date:** [March 22, 2008, 8:48pm UTC](https://www.ruby-forum.com/t/naming-error-uninitialized-constant-actionrecord/132660/3 "2008-03-22T20:48:03Z")

</div>

David A. Black wrote:

> Hi –
> 
> On Sat, 22 Mar 2008, Kelly T. wrote:
> 
> > has\_many :works  
> > Showing composer/show.html.erb where line #5 raised:
> > 
> > uninitialized constant ActionRecord
> 
> My fault. It says ActionRecord in the book; it should be ActiveRecord.  
> Not my finest hour, apparently. But hang in there – there’s some  
> really good stuff in that book 🙂
> 
> David
> 
> –  
> Upcoming Rails training from David A. Black and Ruby Power and Light:  
> ADVANCING WITH RAILS April 14-17 New York City  
> INTRO TO RAILS June 9-12 Berlin  
> ADVANCING WITH RAILS June 16-19 Berlin  
> CORE RAILS June 24-27 London (Skills Matter)  
> See [http://www.rubypal.com](http://www.rubypal.com) for more info!

Doh, I should have realized that when there was no reference to  
“ActionRecord” on google.

Thanks for the quick reply. I love the book by the way. I’m new to  
programming and I was trying to struggle through “Building Your Own Ruby  
On Rails Web Applications.” A friend of mine recommended “Ruby for  
Rails” as a better introduction book. It’s exactly what I needed,  
everything just clicks. =)
