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". -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
David A. Black
2008-Mar-22 19:39 UTC
Re: Naming Error: "uninitialized constant ActionRecord"
Hi -- On Sat, 22 Mar 2008, Kelly Tanguay wrote:> > 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 > > Here''s the actual error: > NameError in Composer#show > > Showing composer/show.html.erb where line #5 raised: > > uninitialized constant ActionRecord<blush/> 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 for more info! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Kelly Tanguay
2008-Mar-22 19:48 UTC
Re: Naming Error: "uninitialized constant ActionRecord"
David A. Black wrote:> Hi -- > > On Sat, 22 Mar 2008, Kelly Tanguay wrote: > >> has_many :works >> Showing composer/show.html.erb where line #5 raised: >> >> uninitialized constant ActionRecord > > <blush/> > > 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 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. =) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---