Hi Everyone, I''m a newbie to Rails, and I just finished going through the cookbook tutorial. I''m now trying to build my own application, and I''m trying to add more inputs to the edit view to modify data in other tables. Below is the controller code where I am having trouble. PartsLocation is another table (like Part) in the database, and that is the line where I get the error. class PartController < ApplicationController scaffold :part def list @parts = Part.find_all end def edit @part = Part.find(@params["id"]) @partslocation = PartsLocation.find(@params["partnumber"]) end end Below is the error I am seeing related to the PartsLocation table, but I have no idea why PartsLocation is uninitialized, but Part is initialized. Any help is appreciated! Thanks, Paul NameError in Part#edit uninitialized constant PartsLocation RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:200:in `const_missing'' #{RAILS_ROOT}/app/controllers/part_controller.rb:10:in `edit'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:200:in `const_missing'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:853:in `perform_action_without_filters'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/filters.rb:332:in `perform_action_without_benchmark'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/rescue.rb:82:in `perform_action'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:in `process_without_session_management_support'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/session_management.rb:116:in `process'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in `dispatch'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:in `handle_dispatch'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:83:in `service'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:in `dispatch'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59 C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in `require'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28 C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in `require'' script/server:3 C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:200:in `const_missing'' #{RAILS_ROOT}/app/controllers/part_controller.rb:10:in `edit'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:853:in `perform_action_without_filters'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/filters.rb:332:in `perform_action_without_benchmark'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/rescue.rb:82:in `perform_action'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:in `process_without_session_management_support'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/session_management.rb:116:in `process'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in `dispatch'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:in `handle_dispatch'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:83:in `service'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:in `dispatch'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59 C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in `require'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28 C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'' C:/RUBYON~1/INSTAN~1.0/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in `require'' script/server:3 This error occured while loading the following files: parts_location.rb Request Parameters: {"id"=>"1"} Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} -- Posted via http://www.ruby-forum.com/.
> > class PartController < ApplicationController > scaffold :part > > def list > @parts = Part.find_all > end > > def edit > @part = Part.find(@params["id"]) > @partslocation = PartsLocation.find(@params["partnumber"]) > end > endmy guess is you are looking for something like this... class PartController < ApplicationController scaffold :part def list... def edit @part = Part.find(params["id"]) @partslocation = PartLocations.find_by_partnumber(params["partnumber") end end The error you are getting is because it cannot find the ''parts_location'' model. Probably you either have it defined in ''part_locations'' or ''partslocation''. Your second search will fail unless "partnumber" is the primary key for that table. _Kevin -- Posted via http://www.ruby-forum.com/.
On Jan 12, 2006, at 4:39 PM, Paul Hackmann wrote:> Hi Everyone, > > I''m a newbie to Rails, and I just finished going through the > cookbook > tutorial. I''m now trying to build my own application, and I''m > trying to > add more inputs to the edit view to modify data in other tables. > Below > is the controller code where I am having trouble. PartsLocation is > another table (like Part) in the database, and that is the line > where I > get the error. > > class PartController < ApplicationController > scaffold :part > > def list > @parts = Part.find_all > end > > def edit > @part = Part.find(@params["id"]) > @partslocation = PartsLocation.find(@params["partnumber"]) > end > end >Scaffolding is great, but if you are going to step beyond the bounds of the basics, then you have to get in there and get your hands dirty. The error is caused by the lack of: model :parts_location But if you are using 2 models, you need to specify them both, like model :part, :parts_location In either case, you''ll need to ditch the scaffold, and do it for real now.
I tried both Kevin and Lori''s suggestions, but neither seemed to help at all. I think part of my problem is that it is looking for a parts_location.rb file, and my model file is partslocation.rb. Why is it putting the underscore in there? As far as ditching the scaffolding goes, I was hoping to replace it a bit at a time by removing list, then edit, etc. I know it will eventually be gone. Thanks, Paul -- Posted via http://www.ruby-forum.com/.
On 1/14/06, Paul Hackmann <shackman@alpinecom.net> wrote:> I tried both Kevin and Lori''s suggestions, but neither seemed to help at > all. I think part of my problem is that it is looking for a > parts_location.rb file, and my model file is partslocation.rb. Why is > it putting the underscore in there? > > As far as ditching the scaffolding goes, I was hoping to replace it a > bit at a time by removing list, then edit, etc. I know it will > eventually be gone.Your model should be part_location.rb. Didn''t you create your model via $ script/generate model PartLocation?
Joe Van Dyk wrote:> On 1/14/06, Paul Hackmann <shackman@alpinecom.net> wrote: >> I tried both Kevin and Lori''s suggestions, but neither seemed to help at >> all. I think part of my problem is that it is looking for a >> parts_location.rb file, and my model file is partslocation.rb. Why is >> it putting the underscore in there? >> >> As far as ditching the scaffolding goes, I was hoping to replace it a >> bit at a time by removing list, then edit, etc. I know it will >> eventually be gone. > > Your model should be part_location.rb. Didn''t you create your model via > $ script/generate model PartLocation?I believe I did: ruby script\generate model partslocation Paul -- Posted via http://www.ruby-forum.com/.
On 1/14/06, Paul Hackmann <shackman@alpinecom.net> wrote:> Joe Van Dyk wrote: > > On 1/14/06, Paul Hackmann <shackman@alpinecom.net> wrote: > >> I tried both Kevin and Lori''s suggestions, but neither seemed to help at > >> all. I think part of my problem is that it is looking for a > >> parts_location.rb file, and my model file is partslocation.rb. Why is > >> it putting the underscore in there? > >> > >> As far as ditching the scaffolding goes, I was hoping to replace it a > >> bit at a time by removing list, then edit, etc. I know it will > >> eventually be gone. > > > > Your model should be part_location.rb. Didn''t you create your model via > > $ script/generate model PartLocation? > > I believe I did: > > ruby script\generate model partslocationShould''ve used script/generate model parts_location (or PartsLocation). That''s what the controller expects to find.
On 1/14/06, Joe Van Dyk <joevandyk@gmail.com> wrote:> On 1/14/06, Paul Hackmann <shackman@alpinecom.net> wrote: > > Joe Van Dyk wrote: > > > On 1/14/06, Paul Hackmann <shackman@alpinecom.net> wrote: > > >> I tried both Kevin and Lori''s suggestions, but neither seemed to help at > > >> all. I think part of my problem is that it is looking for a > > >> parts_location.rb file, and my model file is partslocation.rb. Why is > > >> it putting the underscore in there? > > >> > > >> As far as ditching the scaffolding goes, I was hoping to replace it a > > >> bit at a time by removing list, then edit, etc. I know it will > > >> eventually be gone. > > > > > > Your model should be part_location.rb. Didn''t you create your model via > > > $ script/generate model PartLocation? > > > > I believe I did: > > > > ruby script\generate model partslocation > > Should''ve used script/generate model parts_location (or > PartsLocation). That''s what the controller expects to find.In any event, I bet your model is called Partslocation, right? Your controller is looking for PartsLocation.
Joe Van Dyk wrote:> On 1/14/06, Joe Van Dyk <joevandyk@gmail.com> wrote: >> > >> eventually be gone. >> > > >> > > Your model should be part_location.rb. Didn''t you create your model via >> > > $ script/generate model PartLocation? >> > >> > I believe I did: >> > >> > ruby script\generate model partslocation >> >> Should''ve used script/generate model parts_location (or >> PartsLocation). That''s what the controller expects to find. > > In any event, I bet your model is called Partslocation, right? Your > controller is looking for PartsLocation.Now I feel like an idiot. All that I needed was a lowercase L in Partslocation. It worked just fine after I changed it. Nevertheless, thanks for the help everyone. Thanks, Paul -- Posted via http://www.ruby-forum.com/.
I have a single table inheritance model for some classes Payment < ActiveRecord::Base CreditCardPayment < Payment ECheckPayment < Payment ManualPayment < Payment they all get persisted to the payments table I''m getting an error: ''uninitialized constant Payment'' when trying to create a new instance of any of these classes. At one point in my process I store the payment in a session variable, but I''ve it seems random as to when this happens: before or after that gets set. I even tried explicitly requiring the payment class in the sub classes, and still get the error. I''m using Webrick on ruby 1.8.3 installed on cygwin on a Windows XP machine. Any ideas what''s going on? As I''m sure we all are, I''m under a time crunch, and this is an unexpected error. Please help! -- Posted via http://www.ruby-forum.com/.
Tony Hillerson wrote:> I have a single table inheritance model for some classes > Payment < ActiveRecord::Base > CreditCardPayment < Payment > ECheckPayment < Payment > ManualPayment < Payment > > they all get persisted to the payments tableDo you have a ''type'' column in the payments table? I presume you do, but it''s always best to check...> I''m using Webrick on ruby 1.8.3 installed on cygwin on a Windows XP > machine.That could be a source of problems: the Rails site specifically recommends against 1.8.3. I''d ditch cygwin ruby and use the one-click installer if I were you, just to get rid of the question mark. It''s working fine for me. -- Alex