Ruby/Rails n00b here so go easy on me... I''ve been wracking my brain trying to figure out what is wrong here. I''ve checked all my models for the appropriate belongs_to, has_many, etc. I''ve checked to make sure I''m using singular and plurals in the right spot. I''ve checked my syntax around all my "within"''s and nothing seems to fix it. When I try to pull up the employees index page I get the following message. However if I remove the "belongs_to", "has_many" and "has_and_belongs_to_many" ''s from my model, it works just fine: ==================NameError in Employees#index undefined local variable or method `within'' for Document:Class /app/models/document.rb:8 (eval):5:in `has_and_belongs_to_many'' /app/models/category.rb:3 (eval):5:in `has_many'' /app/models/department.rb:3 (eval):5:in `belongs_to'' /app/models/employee.rb:2 app/controllers/employees_controller.rb:8:in `list'' app/controllers/employees_controller.rb:3:in `index'' Show framework trace c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/base.rb:792:in `method_missing'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:38:in `require_or_load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:21:in `depend_on'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:29:in `associate_with'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:172:in `require_association'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:172:in `require_association'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/associations.rb:679:in `require_association_class'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/associations.rb:552:in `has_and_belongs_to_many_without_reflection'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:38:in `require_or_load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:21:in `depend_on'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:29:in `associate_with'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:172:in `require_association'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:172:in `require_association'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/associations.rb:679:in `require_association_class'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/associations.rb:291:in `has_many_without_reflection'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:38:in `require_or_load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:21:in `depend_on'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:29:in `associate_with'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:172:in `require_association'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:172:in `require_association'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/associations.rb:679:in `require_association_class'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/associations.rb:436:in `belongs_to_without_reflection'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:38:in `require_or_load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:21:in `depend_on'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:171:in `require_dependency'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:171:in `require_dependency'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:183:in `const_missing'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/../../inflector.rb:59:in `const_get'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/../../inflector.rb:59:in `constantize'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/../../inflector.rb:58:in `inject'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/../../inflector.rb:58:in `each'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/../../inflector.rb:58:in `inject'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/../../inflector.rb:58:in `constantize'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/inflections.rb:44:in `constantize'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/pagination.rb:169:in `paginator_and_collection_for'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/pagination.rb:111:in `paginate'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/base.rb:748:in `send'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/base.rb:748:in `perform_action_without_filters'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/filters.rb:295:in `perform_action_without_benchmark'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/benchmarking.rb:41:in `perform_action_without_rescue'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/benchmarking.rb:41:in `measure'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/benchmarking.rb:41:in `perform_action_without_rescue'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/rescue.rb:80:in `perform_action'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/base.rb:348:in `send'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/base.rb:348:in `process'' c:/ruby/lib/ruby/gems/1.8/gems/rails-0.13.0/lib/dispatcher.rb:32:in `dispatch'' /railsapp/public/dispatch.cgi:10 This error occured while loading the following files: employee.rb department.rb category.rb document.rb ================= ======employee.rb=====class Employee < ActiveRecord::Base belongs_to :department belongs_to :location has_many :versions has_and_belongs_to_many :roles validates_associated :locations, :roles, :versions validates_length_of :first, :within=>1..50 validates_length_of :last, :within=>1..50 validates_length_of :resp, :maximum => 3 validates_format_of :resp_before_type_cast, :with => /([0-9]+)/, :message=>"Only numbers are allowed in this field." validates_length_of :office, :within=>0..13 validates_length_of :cell, :within=>0..13 validates_length_of :title, :within=>0..50 validates_format_of :notary_before_type_cast, :with => /[01]/, :message=>"Must be a 0 or 1." validates_format_of :active_before_type_cast, :with => /[01]/, :message=>"Must be a 0 or 1." end =========== Here''s my MySQL dump of the employees table: ============================CREATE TABLE `employees` ( `id` int(11) NOT NULL auto_increment, `first` varchar(50) NOT NULL default '''', `last` varchar(50) NOT NULL default '''', `resp` tinyint(3) default NULL, `hire_date` date default NULL, `office` varchar(13) default NULL, `cell` varchar(13) default NULL, `title` varchar(50) default NULL, `sig_file` varchar(50) default NULL, `notary` tinyint(1) NOT NULL default ''0'', `active` tinyint(1) NOT NULL default ''1'', `location_id` int(11) default NULL, `department_id` int(11) default NULL, `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `updated_on` timestamp NOT NULL default ''0000-00-00 00:00:00'', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; ========================== Please help! Marc ==================DISCLAIMER===============================This email may contain confidential and privileged material for the sole use of the intended recipient. Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies of it from your system. The sender accepts no responsibility for viruses and it is your responsibility to scan attachments (if any). No contracts may be concluded on behalf of the sender by means of email communications unless expressly stated to the contrary. ==================DISCLAIMER================================
Ruby/Rails n00b here so go easy on me... I''ve been wracking my brain trying to figure out what is wrong here. I''ve checked all my models for the appropriate belongs_to, has_many, etc. I''ve checked to make sure I''m using singular and plurals in the right spot. I''ve checked my syntax around all my "within"''s and nothing seems to fix it. When I try to pull up the employees index page I get the following message. However if I remove the "belongs_to", "has_many" and "has_and_belongs_to_many" ''s from my model, it works just fine: ==================NameError in Employees#index undefined local variable or method `within'' for Document:Class /app/models/document.rb:8 (eval):5:in `has_and_belongs_to_many'' /app/models/category.rb:3 (eval):5:in `has_many'' /app/models/department.rb:3 (eval):5:in `belongs_to'' /app/models/employee.rb:2 app/controllers/employees_controller.rb:8:in `list'' app/controllers/employees_controller.rb:3:in `index'' Show framework trace c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/base.rb:792:in `method_missing'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:38:in `require_or_load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:21:in `depend_on'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:29:in `associate_with'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:172:in `require_association'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:172:in `require_association'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/associations.rb:679:in `require_association_class'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/associations.rb:552:in `has_and_belongs_to_many_without_reflection'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:38:in `require_or_load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:21:in `depend_on'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:29:in `associate_with'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:172:in `require_association'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:172:in `require_association'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/associations.rb:679:in `require_association_class'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/associations.rb:291:in `has_many_without_reflection'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:38:in `require_or_load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:21:in `depend_on'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:29:in `associate_with'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:172:in `require_association'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:172:in `require_association'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/associations.rb:679:in `require_association_class'' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.11.0/lib/active_record/associations.rb:436:in `belongs_to_without_reflection'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:193:in `load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:38:in `require_or_load'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:21:in `depend_on'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:171:in `require_dependency'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:171:in `require_dependency'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/dependencies.rb:183:in `const_missing'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/../../inflector.rb:59:in `const_get'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/../../inflector.rb:59:in `constantize'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/../../inflector.rb:58:in `inject'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/../../inflector.rb:58:in `each'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/../../inflector.rb:58:in `inject'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/../../inflector.rb:58:in `constantize'' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.1.0/lib/active_support/core_ext/string/inflections.rb:44:in `constantize'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/pagination.rb:169:in `paginator_and_collection_for'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/pagination.rb:111:in `paginate'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/base.rb:748:in `send'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/base.rb:748:in `perform_action_without_filters'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/filters.rb:295:in `perform_action_without_benchmark'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/benchmarking.rb:41:in `perform_action_without_rescue'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/benchmarking.rb:41:in `measure'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/benchmarking.rb:41:in `perform_action_without_rescue'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/rescue.rb:80:in `perform_action'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/base.rb:348:in `send'' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.9.0/lib/action_controller/base.rb:348:in `process'' c:/ruby/lib/ruby/gems/1.8/gems/rails-0.13.0/lib/dispatcher.rb:32:in `dispatch'' /railsapp/public/dispatch.cgi:10 This error occured while loading the following files: employee.rb department.rb category.rb document.rb ================= ======employee.rb=====class Employee < ActiveRecord::Base belongs_to :department belongs_to :location has_many :versions has_and_belongs_to_many :roles validates_associated :locations, :roles, :versions validates_length_of :first, :within=>1..50 validates_length_of :last, :within=>1..50 validates_length_of :resp, :maximum => 3 validates_format_of :resp_before_type_cast, :with => /([0-9]+)/, :message=>"Only numbers are allowed in this field." validates_length_of :office, :within=>0..13 validates_length_of :cell, :within=>0..13 validates_length_of :title, :within=>0..50 validates_format_of :notary_before_type_cast, :with => /[01]/, :message=>"Must be a 0 or 1." validates_format_of :active_before_type_cast, :with => /[01]/, :message=>"Must be a 0 or 1." end =========== Here''s my MySQL dump of the employees table: ============================CREATE TABLE `employees` ( `id` int(11) NOT NULL auto_increment, `first` varchar(50) NOT NULL default '''', `last` varchar(50) NOT NULL default '''', `resp` tinyint(3) default NULL, `hire_date` date default NULL, `office` varchar(13) default NULL, `cell` varchar(13) default NULL, `title` varchar(50) default NULL, `sig_file` varchar(50) default NULL, `notary` tinyint(1) NOT NULL default ''0'', `active` tinyint(1) NOT NULL default ''1'', `location_id` int(11) default NULL, `department_id` int(11) default NULL, `created_on` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `updated_on` timestamp NOT NULL default ''0000-00-00 00:00:00'', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; ========================== Please help! Thanks, Marc ==================DISCLAIMER===============================This email may contain confidential and privileged material for the sole use of the intended recipient. Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies of it from your system. The sender accepts no responsibility for viruses and it is your responsibility to scan attachments (if any). No contracts may be concluded on behalf of the sender by means of email communications unless expressly stated to the contrary. ==================DISCLAIMER================================
What version of rails are you running? _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Opps forgot to include that... 0.13. I upgraded yesterday and thought that might have been the problem (no I hadn''t tested my app prior to upgrade). So I rebuilt my app using scaffold and then copied over my old model files to the newly built app.>>> sean-5W9FBhQXBOtBDgjK7y7TUQ@public.gmane.org 07/07/05 10:42AM >>>What version of rails are you running? ==================DISCLAIMER===============================This email may contain confidential and privileged material for the sole use of the intended recipient. Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies of it from your system. The sender accepts no responsibility for viruses and it is your responsibility to scan attachments (if any). No contracts may be concluded on behalf of the sender by means of email communications unless expressly stated to the contrary. ==================DISCLAIMER================================