Naming Error: "uninitialized constant ActionRecord"

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”.

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 :slight_smile:

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 for more info!

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 :slight_smile:

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 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. =)