James Labocki
2006-Aug-17 12:38 UTC
[Rails] NameError in AdminController#index building scaffold
I''m a pretty big newbie with ROR, but when following a tutorial I encounter an ugly error when building a scaffold. Here is my environment Dev system: - Windows XP - java version "1.5.0_06" - MySQL java version "1.5.0_06" - Ruby 1.8.4 - Ruby Gems 0.9.0 - Gem install mysql Successfully installed mysql-2.7.1-mswin32 Installing ri documentation for mysql-2.7.1-mswin32... Installing RDoc documentation for mysql-2.7.1-mswin32... - Table in ediweb database mysql> desc users; +----------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +----------------+-------------+------+-----+---------+----------------+ | user_id | int(11) | NO | PRI | NULL | auto_increment | | user_login | varchar(50) | NO | | | | | user_firstname | varchar(50) | NO | | | | | user_lastname | varchar(50) | NO | | | | | user_role | varchar(50) | NO | | | | +----------------+-------------+------+-----+---------+----------------+ 5 rows in set (0.18 sec) I am also connecting to Subversion on a linux system as my Repo. When I start my server I am able to view several other controllers. I stop my server and create a scaffold in RadRails. ediweb> ruby script/generate scaffold Users Admin exists app/controllers/ exists app/helpers/ exists app/views/admin exists test/functional/ dependency model exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/users.rb create test/unit/users_test.rb create test/fixtures/users.yml identical app/views/admin/_form.rhtml create app/views/admin/list.rhtml create app/views/admin/show.rhtml create app/views/admin/new.rhtml create app/views/admin/edit.rhtml create app/controllers/admin_controller.rb create test/functional/admin_controller_test.rb create app/helpers/admin_helper.rb create app/views/layouts/admin.rhtml create public/stylesheets/scaffold.css Looks like no problem, but then I check the page: NameError in AdminController#index uninitialized constant User RAILS_ROOT: ./script/../config/.. Application Trace | Framework Trace | Full Trace D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:123:in `const_missing'' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:131:in `const_missing'' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/inflector.rb:161:in `constantize'' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/core_ext/string/inflections.rb:59:in `constantize'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/pagination.rb:194:in `paginator_and_collection_for'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/pagination.rb:129:in `paginate'' #{RAILS_ROOT}/app/controllers/admin_controller.rb:12:in `list'' #{RAILS_ROOT}/app/controllers/admin_controller.rb:3:in `index'' -e:4 D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:123:in `const_missing'' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:131:in `const_missing'' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/inflector.rb:161:in `constantize'' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/core_ext/string/inflections.rb:59:in `constantize'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/pagination.rb:194:in `paginator_and_collection_for'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/pagination.rb:129:in `paginate'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in `perform_action_without_filters'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in `perform_action_without_benchmark'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' D:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in `perform_action'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `process_without_filters'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in `process_without_session_management_support'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in `process'' D:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch'' D:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:115:in `handle_dispatch'' D:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:81:in `service'' D:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'' D:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'' D:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'' D:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'' D:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'' D:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'' D:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'' D:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'' D:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:67:in `dispatch'' D:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/servers/webrick.rb:59 D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'' D:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/server.rb:30 D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'' script/server:3 D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:123:in `const_missing'' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:131:in `const_missing'' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/inflector.rb:161:in `constantize'' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/core_ext/string/inflections.rb:59:in `constantize'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/pagination.rb:194:in `paginator_and_collection_for'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/pagination.rb:129:in `paginate'' #{RAILS_ROOT}/app/controllers/admin_controller.rb:12:in `list'' #{RAILS_ROOT}/app/controllers/admin_controller.rb:3:in `index'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:941:in `perform_action_without_filters'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:368:in `perform_action_without_benchmark'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' D:/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/benchmarking.rb:69:in `perform_action_without_rescue'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/rescue.rb:82:in `perform_action'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/base.rb:408:in `process_without_filters'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/filters.rb:377:in `process_without_session_management_support'' D:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/session_management.rb:117:in `process'' D:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/dispatcher.rb:38:in `dispatch'' D:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:115:in `handle_dispatch'' D:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:81:in `service'' D:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'' D:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'' D:/ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'' D:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'' D:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'' D:/ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'' D:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'' D:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'' D:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/webrick_server.rb:67:in `dispatch'' D:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/servers/webrick.rb:59 D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'' D:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/commands/server.rb:30 D:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'' D:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:147:in `require'' script/server:3 -e:4 This error occured while loading the following files: user.rb Request Parameters: None Show session dump --- flash: !map:ActionController::Flash::FlashHash {} Response Headers: {"cookie"=>[], "Cache-Control"=>"no-cache"} I have tried building the scaffold with users and admin instead of Users and Admin, but it''s still not working! Also, I verified MySQL connectivity from ruby server to the database by doing the following: ActiveRecord::Base.connection.select_all(''desc users'') => [{"Extra"=>"auto_increment", "Default"=>nil, "Null"=>"NO", "Type"=>"int(11)", "Field"=>"user_id", "Key"=>"PRI"}, {"Extra"=>"", "Default"=>"", "Null"=>"NO", "Type"=>"varchar(50)", "Field"=>"user_login", "Key"=>""}, {"Extra"=>"", "Default"=>"", "Null"=>"NO", "Type"=>"varchar(50)", "Field"=>"user_firstname", "Key"=>""}, {"Extra"=>"", "Default"=>"", "Null"=>"NO", "Type"=>"varchar(50)", "Field"=>"user_lastname", "Key"=>""}, {"Extra"=>"", "Default"=>"", "Null"=>"NO", "Type"=>"varchar(50)", "Field"=>"user_role", "Key"=>""}]>> ActiveRecord::Base.connection.select_all(''select * from users'')ActiveRecord::Base.connection.select_all(''select * from users'') => [] My question is I do have one record in the table but the ''select *'' query doesn''t come back with nothing. Any help would be appreciated! :) Thanks James -- Posted via http://www.ruby-forum.com/.
James Labocki
2006-Aug-17 12:38 UTC
[Rails] Re: NameError in AdminController#index building scaffold
I forgot by database.yml has the following for the dev environment: development: adapter: mysql database: ediweb username: root password: ******** host: localhost -- Posted via http://www.ruby-forum.com/.
James Labocki
2006-Aug-17 12:46 UTC
[Rails] Re: NameError in AdminController#index building scaffold
One more note, I didn''t have any records in the database! When I inserted some I am still able to connect through the development console -- but still gettig the same error from the http://localhost:3000/admin --- any ideas?>> ActiveRecord::Base.connection.select_all(''select* from users'')ActiveRecord::Base.connection.select_all(''select* from users'') => [{"user_login"=>"jsmith", "user_firstname"=>"joe", "user_id"=>"1", "user_role"=>"admin", "user_lastname"=>"smith"}, {"user_login"=>"bsmith", "user_firstname"=>"bob", "user_id"=>"2", "user_role"=>"user", "user_lastname"=>"smith"}] -- Posted via http://www.ruby-forum.com/.
James Labocki
2006-Aug-17 12:54 UTC
[Rails] Re: NameError in AdminController#index building scaffold
Also, my model users.rb: class Users < ActiveRecord::Base end -- Posted via http://www.ruby-forum.com/.
James Labocki
2006-Aug-17 13:12 UTC
[Rails] Re: NameError in AdminController#index building scaffold
I was able to solve my own problem. I generated the scaffold using ''ruby script/generate scaffold user Admin'' ediweb> ruby script/generate scaffold user Admin exists app/controllers/ exists app/helpers/ exists app/views/admin exists test/functional/ dependency model exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/user.rb create test/unit/user_test.rb create test/fixtures/users.yml create app/views/admin/_form.rhtml create app/views/admin/list.rhtml create app/views/admin/show.rhtml create app/views/admin/new.rhtml create app/views/admin/edit.rhtml create app/controllers/admin_controller.rb create test/functional/admin_controller_test.rb create app/helpers/admin_helper.rb create app/views/layouts/admin.rhtml create public/stylesheets/scaffold.css How did ruby know that my database table was ''users'' when I generated the scaffold as ''user''? I''m sorry if this is a dumb question :) -- Posted via http://www.ruby-forum.com/.
Rob Gabaree
2006-Aug-17 14:20 UTC
[Rails] Re: NameError in AdminController#index building scaffold
Unless you change it, it always looks for the plural form of the model as the table.. so a "person" model would have a "people" table, "cat" model would have "cats" table, etc. This is pretty basic and covered in "Agile Web Development in Rails" as well as a lot of online tutorials. On Aug 17, 2006, at 9:11 AM, James Labocki wrote:> I was able to solve my own problem. I generated the scaffold using > ''ruby script/generate scaffold user Admin'' > > ediweb> ruby script/generate scaffold user Admin > exists app/controllers/ > exists app/helpers/ > exists app/views/admin > exists test/functional/ > dependency model > exists app/models/ > exists test/unit/ > exists test/fixtures/ > create app/models/user.rb > create test/unit/user_test.rb > create test/fixtures/users.yml > create app/views/admin/_form.rhtml > create app/views/admin/list.rhtml > create app/views/admin/show.rhtml > create app/views/admin/new.rhtml > create app/views/admin/edit.rhtml > create app/controllers/admin_controller.rb > create test/functional/admin_controller_test.rb > create app/helpers/admin_helper.rb > create app/views/layouts/admin.rhtml > create public/stylesheets/scaffold.css > > > How did ruby know that my database table was ''users'' when I generated > the scaffold as ''user''? I''m sorry if this is a dumb question :) > > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails