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: <p>Click on any work to see all available editions of that work.</p> 4: <ul> 5: <% @composer.works.each do |w| %> 6: <li><%= 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".