Hi guys, I''m part way through a RoR application, for some reason whenever I add new controllers (using scaffold) I get an uninitialized constant [name of controller] error. The first few controllers work fine, the only thing I can see that I''ve changed is the layout file (but scaffold creates a new layout for each controller so can''t see that being the problem). You can all probably tell I''m new to rails so hoping this is some newb error... the failing controllers can be found at http://spotter.derbyproject.com/exercises/list http://spotter.derbyproject.com/updates/ and working ones are here http://spotter.derbyproject.com/users Just for clarity, Ive been adding controllers as I go, but the last two added have given this error straight after running scaffold (I haven''t made any changes to them). thanks! -- 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 -~----------~----~----~----~------~----~------~--~---
On 13 Apr 2008, at 15:35, Lee Farrar wrote:> > Hi guys, I''m part way through a RoR application, for some reason > whenever I add new controllers (using scaffold) I get an uninitialized > constant [name of controller] error. > > The first few controllers work fine, the only thing I can see that > I''ve > changed is the layout file (but scaffold creates a new layout for > each > controller so can''t see that being the problem). You can all probably > tell I''m new to rails so hoping this is some newb error... >Well it''s nice that we can see the error messages, but the code would be more helpful :-) (eg what''s on exercises_controller on line 12 ?) Fred> the failing controllers can be found at > http://spotter.derbyproject.com/exercises/list > http://spotter.derbyproject.com/updates/ > > and working ones are here > http://spotter.derbyproject.com/users > > Just for clarity, Ive been adding controllers as I go, but the last > two > added have given this error straight after running scaffold (I haven''t > made any changes to them). > > thanks! > -- > 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 -~----------~----~----~----~------~----~------~--~---
good call... sorry mate line 11-13 look like this def list @exercises_pages, @exercises = paginate :exercises, :per_page => 10 end which is the same as was generated for the previous controllers. The page should be generating a list of exercises currently in the database, it might be worth pointing out that exercises/new works, so seems to be just the list method. cheers. -- 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 -~----------~----~----~----~------~----~------~--~---
On 13 Apr 2008, at 15:58, Lee Farrar wrote:> > good call... sorry mate > > line 11-13 look like this > > def list > @exercises_pages, @exercises = paginate :exercises, :per_page => 10 > endis the Class name Exercise or Exercises. I''m going to guess that it''s the latter. paginate is being smart and assuming that if you say exercises, then the name of the model is the singular (ie exercise). I''ll further guess that the difference is that when you created the scaffold you''ve recently been using the plural form, whereas you should be using the singular. Fred> which is the same as was generated for the previous controllers. > The page should be generating a list of exercises currently in the > database, it might be worth pointing out that exercises/new works, so > seems to be just the list method. > > cheers. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 13 Apr 2008, at 15:58, Lee Farrar wrote: > >> >> good call... sorry mate >> >> line 11-13 look like this >> >> def list >> @exercises_pages, @exercises = paginate :exercises, :per_page => 10 >> end > is the Class name Exercise or Exercises. I''m going to guess that it''s > the latter. paginate is being smart and assuming that if you say > exercises, then the name of the model is the singular (ie exercise). > I''ll further guess that the difference is that when you created the > scaffold you''ve recently been using the plural form, whereas you > should be using the singular. > > FredI just ran scaffold exercise and it''s running fine now, thanks Fred! I guess I paid the price for being a little too cocky after i set up the first few controllers. Cheers! Lee -- 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 -~----------~----~----~----~------~----~------~--~---
I have the following models: class Entity < ActiveRecord::Base ... has_many :locations, :dependent => :destroy, :include => :sites has_many :sites, :through => :locations class Site < ActiveRecord::Base has_many :locations has_many :entities, :through => :locations class Location < ActiveRecord::Base belongs_to :entities belongs_to :sites In views/entities/index.html.erb I have this: <% if entity.locations.empty? -%> <%= link_to ''Add Locations'', new_entity_locations_path(entity) -%> <% else -%> <%= link_to ''Edit Locations'', entity_locations_path(entity) -%> <% end -%> And in entities_controller.rb I have this: 10 def index 11 @entities = Entity.find(:all) 12 13 respond_to do |format| 14 format.html # index.html.erb 15 format.xml { render :xml => @entities } 16 end 17 end When I look at views/entities/index I get this error: uninitialized constant Location::Sites ... 64: <% if entity.locations.empty? -%> 65: <%= link_to ''Add Locations'', new_entity_locations_path(entity) -%> 66: <% else -%> ... app/controllers/entities_controller.rb:13:in `index'' I am evidently overlooking something obvious but for the life of me I cannot see what. Another pair of eyes is most welcome. -- 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 -~----------~----~----~----~------~----~------~--~---
On Apr 14, 10:13 pm, James Byrne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I have the following models: > > > class Location < ActiveRecord::Base > > belongs_to :entities > belongs_to :sitesshould be belongs_to :site and belongs_to :entity Fred --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:>> � belongs_to � � � �:entities >> � belongs_to � � � �:sites > > should be belongs_to :site and belongs_to :entity > > FredI had that to begin with but that gave this error: Association named ''sites'' was not found; perhaps you misspelled it? -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It should be singular, not plural. (ie no "s"). Julian. Learn Ruby on Rails! Check out the FREE VIDS (for a limited time) VIDEO #4 coming soon! http://sensei.zenunit.com/ On 15/04/2008, at 9:39 AM, James Byrne wrote:> > Frederick Cheung wrote: >>> � belongs_to � � � �:entities >>> � belongs_to � � � �:sites >> >> should be belongs_to :site and belongs_to :entity >> >> Fred > > I had that to begin with but that gave this error: > > Association named ''sites'' was not found; perhaps you misspelled it? > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Julian Leviston wrote:> It should be singular, not plural. (ie no "s"). > > Julian.I had that originally and got a different error at the same locations: class Location < ActiveRecord::Base belongs_to :entity belongs_to :site Association named ''sites'' was not found; perhaps you misspelled it? -- 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 -~----------~----~----~----~------~----~------~--~---
On 15 Apr 2008, at 14:22, James Byrne wrote:> > Julian Leviston wrote: >> It should be singular, not plural. (ie no "s"). >> >> Julian. > > I had that originally and got a different error at the same locations: > > class Location < ActiveRecord::Base > > belongs_to :entity > belongs_to :site > > > Association named ''sites'' was not found; perhaps you misspelled it?You need to also change it wherever you used location.sites Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 15 Apr 2008, at 14:22, James Byrne wrote: > >> belongs_to :entity >> belongs_to :site >> >> >> Association named ''sites'' was not found; perhaps you misspelled it? > > You need to also change it wherever you used location.sites > > Fred$ find ./ -print | xargs grep ''locations.sites'' $ find ./ -print | xargs grep ''location.sites'' $ find ./ -print | xargs grep ''locations.site'' $ find ./ -print | xargs grep ''location.site'' ... (.svn stuff removed) ./app/views/locations/index.html.erb: <td><%=h location.site_id %></td> ./app/views/locations/new.html.erb: :object => @location.site -%> ./app/views/locations/show.html.erb: <%=h @location.site_id %> $ I cannot seem to find anywhere that I have done this. -- 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 -~----------~----~----~----~------~----~------~--~---
On 15 Apr 2008, at 14:53, James Byrne wrote:> > Frederick Cheung wrote: >> On 15 Apr 2008, at 14:22, James Byrne wrote: >> >>> belongs_to :entity >>> belongs_to :site >>> >>> >>> Association named ''sites'' was not found; perhaps you misspelled it? >> >> You need to also change it wherever you used location.sites >> >> Fred > > $ find ./ -print | xargs grep ''locations.sites'' > $ find ./ -print | xargs grep ''location.sites'' > $ find ./ -print | xargs grep ''locations.site'' > $ find ./ -print | xargs grep ''location.site'' > ... (.svn stuff removed) > ./app/views/locations/index.html.erb: <td><%=h location.site_id > %></td> > ./app/views/locations/new.html.erb: :object => > @location.site -%> > ./app/views/locations/show.html.erb: <%=h @location.site_id %> > $ > > I cannot seem to find anywhere that I have done this.Find the line causing that error (it should be in the stack trace). Fred> > -- > 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote: t seem to find anywhere that I have done this.> > Find the line causing that error (it should be in the stack trace). > > FredNameError in Entities#index Showing entities/index.html.erb where line #64 raised: uninitialized constant Location::Sites Extracted source (around line #64): 61: <% end -%> 62: </td> 63: <td> 64: <% if entity.locations.empty? -%> 65: <%= link_to ''Add Locations'', new_entity_locations_path(entity) -%> 66: <% else -%> 67: <%= link_to ''Edit Locations'', entity_locations_path(entity) -%> vendor/rails/activesupport/lib/active_support/dependencies.rb:478:in `const_missing'' vendor/rails/activerecord/lib/active_record/base.rb:1764:in `compute_type'' vendor/rails/activerecord/lib/active_record/reflection.rb:125:in `send'' vendor/rails/activerecord/lib/active_record/reflection.rb:125:in `klass'' vendor/rails/activerecord/lib/active_record/associations.rb:1602:in `initialize'' vendor/rails/activerecord/lib/active_record/associations.rb:1498:in `new'' vendor/rails/activerecord/lib/active_record/associations.rb:1498:in `build_join_association'' vendor/rails/activerecord/lib/active_record/associations.rb:1481:in `build'' vendor/rails/activerecord/lib/active_record/associations.rb:1484:in `build'' vendor/rails/activerecord/lib/active_record/associations.rb:1483:in `each'' vendor/rails/activerecord/lib/active_record/associations.rb:1483:in `build'' vendor/rails/activerecord/lib/active_record/associations.rb:1424:in `initialize'' vendor/rails/activerecord/lib/active_record/calculations.rb:180:in `new'' vendor/rails/activerecord/lib/active_record/calculations.rb:180:in `construct_calculation_sql'' vendor/rails/activerecord/lib/active_record/calculations.rb:209:in `execute_simple_calculation'' vendor/rails/activerecord/lib/active_record/calculations.rb:123:in `calculate'' vendor/rails/activerecord/lib/active_record/calculations.rb:119:in `catch'' vendor/rails/activerecord/lib/active_record/calculations.rb:119:in `calculate'' vendor/rails/activerecord/lib/active_record/calculations.rb:46:in `count'' vendor/rails/activerecord/lib/active_record/associations/has_many_association.rb:96:in `count_records'' vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:108:in `size'' vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:121:in `empty?'' app/views/entities/index.html.erb:64:in `_run_erb_47app47views47entities47index46html46erb'' app/views/entities/index.html.erb:28:in `each'' app/views/entities/index.html.erb:28:in `_run_erb_47app47views47entities47index46html46erb'' vendor/rails/actionpack/lib/action_view/base.rb:645:in `send'' vendor/rails/actionpack/lib/action_view/base.rb:645:in `compile_and_render_template'' vendor/rails/actionpack/lib/action_view/base.rb:367:in `render_template'' vendor/rails/actionpack/lib/action_view/base.rb:316:in `render_file'' vendor/rails/actionpack/lib/action_controller/base.rb:1101:in `render_for_file'' vendor/rails/actionpack/lib/action_controller/base.rb:858:in `render_with_no_layout'' vendor/rails/actionpack/lib/action_controller/base.rb:872:in `render_with_no_layout'' vendor/rails/actionpack/lib/action_controller/layout.rb:261:in `render_without_benchmark'' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:51:in `render'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:51:in `render'' vendor/rails/actionpack/lib/action_controller/mime_responds.rb:131:in `send'' vendor/rails/actionpack/lib/action_controller/mime_responds.rb:131:in `custom'' vendor/rails/actionpack/lib/action_controller/mime_responds.rb:156:in `call'' vendor/rails/actionpack/lib/action_controller/mime_responds.rb:156:in `respond'' vendor/rails/actionpack/lib/action_controller/mime_responds.rb:150:in `each'' vendor/rails/actionpack/lib/action_controller/mime_responds.rb:150:in `respond'' vendor/rails/actionpack/lib/action_controller/mime_responds.rb:107:in `respond_to'' app/controllers/entities_controller.rb:13:in `index'' vendor/rails/actionpack/lib/action_controller/base.rb:1159:in `send'' vendor/rails/actionpack/lib/action_controller/base.rb:1159:in `perform_action_without_filters'' vendor/rails/actionpack/lib/action_controller/filters.rb:699:in `call_filters'' vendor/rails/actionpack/lib/action_controller/filters.rb:691:in `perform_action_without_benchmark'' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure'' vendor/rails/actionpack/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'' vendor/rails/actionpack/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'' vendor/rails/actionpack/lib/action_controller/caching.rb:678:in `perform_action'' vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:33:in `cache'' vendor/rails/activerecord/lib/active_record/query_cache.rb:8:in `cache'' vendor/rails/actionpack/lib/action_controller/caching.rb:677:in `perform_action'' vendor/rails/actionpack/lib/action_controller/base.rb:524:in `send'' vendor/rails/actionpack/lib/action_controller/base.rb:524:in `process_without_filters'' vendor/rails/actionpack/lib/action_controller/filters.rb:687:in `process_without_session_management_support'' vendor/rails/actionpack/lib/action_controller/session_management.rb:123:in `process'' vendor/rails/actionpack/lib/action_controller/base.rb:388:in `process'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:171:in `handle_request'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:115:in `dispatch'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'' vendor/rails/actionpack/lib/action_controller/dispatcher.rb:9:in `dispatch'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:76:in `process'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:74:in `synchronize'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:74:in `process'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:159:in `process_client'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `each'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `process_client'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `initialize'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `new'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `initialize'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `new'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:282:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `each'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:128:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/command.rb:212:in `run'' /usr/lib/ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:281 vendor/rails/activesupport/lib/active_support/dependencies.rb:489:in `load'' vendor/rails/activesupport/lib/active_support/dependencies.rb:489:in `load'' vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'' vendor/rails/activesupport/lib/active_support/dependencies.rb:489:in `load'' vendor/rails/railties/lib/commands/servers/mongrel.rb:64 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'' /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in `require'' vendor/rails/activesupport/lib/active_support/dependencies.rb:342:in `new_constants_in'' vendor/rails/activesupport/lib/active_support/dependencies.rb:496:in `require'' vendor/rails/railties/lib/commands/server.rb:39 script/server:3:in `require'' script/server:3 The code in entities__controller around line 13 is: 10: def index 11: @entities = Entity.find(:all) 12: 13: respond_to do |format| 14: format.html # index.html.erb 15: format.xml { render :xml => @entities } 16: end 17: end -- 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 -~----------~----~----~----~------~----~------~--~---
On 15 Apr 2008, at 15:31, James Byrne wrote:> > Frederick Cheung wrote: > t seem to find anywhere that I have done this. >> >> Find the line causing that error (it should be in the stack trace). >> >> Fred > > NameError in Entities#index > > Showing entities/index.html.erb where line #64 raised: > > uninitialized constant Location::Sites >Which probably means there''s something not right in location.rb Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 15 Apr 2008, at 15:31, James Byrne wrote: > >> Showing entities/index.html.erb where line #64 raised: >> >> uninitialized constant Location::Sites >> > Which probably means there''s something not right in location.rb > > FredThis is the entirety of location.rb: class Location < ActiveRecord::Base belongs_to :entity belongs_to :site end If I use the singular fors for entity and site in the belongs_to, which is what I did initially, then I get this error in entities/index at line 64: Association named ''sites'' was not found; perhaps you misspelled it? If I use the plural forms then I get this message instead, but at exactly the same places: uninitialized constant Location::Sites I cannot see what it is that I am doing wrong here. entity.locations is the collection of locations relating to entities, that might be empty, while location.site should be the the site related to a location in that collection. I cannot tell where this Sites is coming from. I have checked site.rb and the class name is defined as this: class Site < ActiveRecord::Base has_many :locations has_many :entities, :through => :locations SO, what is going on? -- 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 -~----------~----~----~----~------~----~------~--~---
On 15 Apr 2008, at 15:56, James Byrne wrote:> > Frederick Cheung wrote: >> On 15 Apr 2008, at 15:31, James Byrne wrote: >> >>> Showing entities/index.html.erb where line #64 raised: >>> >>> uninitialized constant Location::Sites >>> >> Which probably means there''s something not right in location.rb >> >> Fred > > This is the entirety of location.rb: > > class Location < ActiveRecord::Base > > belongs_to :entity > belongs_to :site > > end > > If I use the singular fors for entity and site in the belongs_to, > which > is what I did initially, then I get this error in entities/index at > line > 64: > > Association named ''sites'' was not found; perhaps you misspelled it? >That means that something is still using the association names sites (eg an :include => :sites). Track it down. Fred>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 15 Apr 2008, at 15:56, James Byrne wrote: > >>> Fred >> If I use the singular fors for entity and site in the belongs_to, >> which >> is what I did initially, then I get this error in entities/index at >> line >> 64: >> >> Association named ''sites'' was not found; perhaps you misspelled it? >> > That means that something is still using the association names sites > (eg an :include => :sites). Track it down. > > FredI grep''ed my entire project and found only these references to sites: $ find ./ -print | xargs grep sites | grep -v ''.svn'' | grep -v ''vendor'' This stuff is just test fixtures and migrations. As far as I am aware none of this should have any effect on running code: ./test/fixtures/sites.yml:# Table name: sites ./db/migrate/022_create_sites.rb: create_table :sites do |t| ./db/migrate/022_create_sites.rb: add_index :sites, [:site_country_code, :site_postal_code], ./db/migrate/022_create_sites.rb: :name => :idxR_sites_country_postal_codes, ./db/migrate/022_create_sites.rb: remove_index :sites, :name => :idxR_sites_country_postal_codes ./db/migrate/022_create_sites.rb: drop_table :sites Binary file ./db/development.sqlite3 matches ./db/schema.rb: create_table "sites", :force => true do |t| ./db/schema.rb: add_index "sites", ["site_country_code", "site_postal_code"], :name => "idxR_sites_country_postal_codes" Binary file ./app/models/.site.rb.swp matches This is the stuff of interest: ./app/models/entity.rb: :include => :sites ./app/models/entity.rb: has_many :sites, :through => :locations ./app/models/site.rb:# Table name: sites Is the :include => :sites in entity.rb the problem? If so then why? ./app/controllers/sites_controller.rb: # GET /sites ./app/controllers/sites_controller.rb: # GET /sites.xml ./app/controllers/sites_controller.rb: @sites = Site.find(:all) ./app/controllers/sites_controller.rb: format.xml { render :xml => @sites } ./app/controllers/sites_controller.rb: # GET /sites/1 ./app/controllers/sites_controller.rb: # GET /sites/1.xml ./app/controllers/sites_controller.rb: # GET /sites/new ./app/controllers/sites_controller.rb: # GET /sites/new.xml ./app/controllers/sites_controller.rb: # GET /sites/1/edit ./app/controllers/sites_controller.rb: # POST /sites ./app/controllers/sites_controller.rb: # POST /sites.xml ./app/controllers/sites_controller.rb: # PUT /sites/1 ./app/controllers/sites_controller.rb: # PUT /sites/1.xml ./app/controllers/sites_controller.rb: # DELETE /sites/1 ./app/controllers/sites_controller.rb: # DELETE /sites/1.xml ./app/controllers/sites_controller.rb: format.html { redirect_to(sites_url) } ./app/views/sites/edit.html.erb:<%= link_to ''Back'', sites_path %> ./app/views/sites/index.html.erb:<h1>Listing sites</h1> ./app/views/sites/index.html.erb:<% for site in @sites %> ./app/views/sites/new.html.erb:<%= link_to ''Back'', sites_path %> ./app/views/sites/show.html.erb:<%= link_to ''Back'', sites_path %> ./app/views/locations/new.html.erb: <%= render :partial => ''sites/site_detail'', ./config/routes.rb: map.resources :sites do |site| You assistance has been greatly appreciated. -- 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 -~----------~----~----~----~------~----~------~--~---
entity.rb looks like this: class Entity < ActiveRecord::Base has_one :client, :dependent => :destroy has_one :vendor, :dependent => :destroy has_many :locations, :dependent => :destroy, :include => :sites has_many :sites, :through => :locations # -- 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 -~----------~----~----~----~------~----~------~--~---
On 15 Apr 2008, at 16:18, James Byrne wrote:> > Frederick Cheung wrote: >> On 15 Apr 2008, at 15:56, James Byrne wrote: >> >>>> Fred >>> If I use the singular fors for entity and site in the belongs_to, >>> which >>> is what I did initially, then I get this error in entities/index at >>> line >>> 64: >>> >>> Association named ''sites'' was not found; perhaps you misspelled it? >>> >> That means that something is still using the association names sites >> (eg an :include => :sites). Track it down. >> >> Fred > > I grep''ed my entire project and found only these references to sites: > > $ find ./ -print | xargs grep sites | grep -v ''.svn'' | grep -v > ''vendor'' > > > Is the :include => :sites in entity.rb the problem? If so then why?Yes. it''s a problem because you''re saying ''when you load location, also load the association sites". But location doesn''t have an association called sites (it does have one called site) Fred --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> On 15 Apr 2008, at 16:18, James Byrne wrote: > >>>> >> ''vendor'' >> >> >> Is the :include => :sites in entity.rb the problem? If so then why? > > Yes. it''s a problem because you''re saying ''when you load location, > also load the association sites". But location doesn''t have an > association called sites (it does have one called site) > > FredAhhhhhrrrrggg... that was it. Thank you! -- 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 -~----------~----~----~----~------~----~------~--~---