Glenn Smith
2005-Mar-30 09:20 UTC
Help - dependencies.rb - `const_missing'': uninitialized constant
I''m trying to get this has_and_belongs_to_many join to work (re: my post from yesterday). I''m getting an error I can''t seem to get by. Help? I now have the following tables: ORGANISATIONS: id (primary key) name REPRESENTATIVES id (primary key) name ORGANISATIONS_REPRESENTATIVES organisation_id representative_id My models are: class Organisation < ActiveRecord::Base has_and_belongs_to_many :representatives end class Representative < ActiveRecord::Base has_and_belongs_to_many :organisations end In organisations_helper.rb I have: module OrganisationsHelper def reps_list(organisation) a = [] for r in organisation.representatives a << r.name end a.join(",") end end In my organisations list view I have: <% @organisations.each do |o| %> <tr> <td><%= reps_list(o) %></td> </tr> <% end %> And obviously in my organisation list controller I have def list @organisations = Organisation.find_all end When I browse to http://127.0.0.1/organisations I get: NameError in Organisations#index Showing /organisations/list.rhtml where line #27 raised C:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.0.3/lib/active_support/dependencies.rb:181:in `const_missing'': uninitialized constant Representatife 27: <td><%= reps_list(o) %></td> 28: </tr> 29: <% end %> 30: Note it says "uninitialized constant Representatife", not "Representative". I guess this is something Rails is doing to the Representative name, because I have no reference to "Representatife" anywhere. Show template trace C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.9.1/lib/active_record/associations/association_proxy.rb:11:in `initialize'' (eval):1:in `initialize'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.9.1/lib/active_record/associations/has_and_belongs_to_many_association.rb:5:in `eval'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.9.1/lib/active_record/associations/association_proxy.rb:11:in `initialize'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.9.1/lib/active_record/associations/has_and_belongs_to_many_association.rb:5:in `initialize'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.9.1/lib/active_record/associations.rb:558:in `new'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.9.1/lib/active_record/associations.rb:558:in `representatives'' C:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.9.1/lib/active_record/associations.rb:554:in `representatives'' /app/helpers/organisations_helper.rb:3:in `reps_list'' (erb):27:in `evaluate_locals'' (erb):17:in `each'' (erb):17:in `evaluate_locals'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_view/base.rb:265:in `evaluate_locals'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_view/base.rb:275:in `rhtml_render'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_view/base.rb:201:in `send'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_view/base.rb:201:in `render_template'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_view/base.rb:181:in `render_file'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/layout.rb:208:in `render_without_benchmark'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/benchmarking.rb:22:in `render'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/benchmarking.rb:22:in `measure'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/benchmarking.rb:22:in `render'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/base.rb:447:in `render_action'' app/controllers/organisations_controller.rb:7:in `index'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/base.rb:700:in `send'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/base.rb:700:in `perform_action_without_filters'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/filters.rb:294:in `perform_action_without_benchmark'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/benchmarking.rb:30:in `perform_action_without_rescue'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/benchmarking.rb:30:in `measure'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/benchmarking.rb:30:in `perform_action_without_rescue'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/rescue.rb:79:in `perform_action'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/base.rb:330:in `send'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/base.rb:330:in `process'' C:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.7.0/lib/action_controller/base.rb:273:in `process'' C:/ruby/lib/ruby/gems/1.8/gems/rails-0.11.1/lib/dispatcher.rb:32:in `dispatch'' C:/src/rails/webac/public/dispatch.cgi:10