Scaffolds! Help

Hi im having problems using scaffolds. Im trying to do something very
simple, I dont understand the error. Hopefully someone can advise me.

  1. I’ve created my project, set my databases as SQLight and ran the
    migration: ruby script/generate migration add_a_new_table

  2. I have then edited the code in db/migrate/001_add_a_new_table to:

class AddANewTable < ActiveRecord::Migration

def self.up
create_table :users do |table|
table.column :name, :string
table.column :address, :string
table.column :postcode, :string
table.column :country, :string
table.column :phone, :string
table.column :email, :string

end

end

def self.down
drop_table :users
end
end

  1. Then I have: rake migrate

  2. When I run:
    script/generate scaffold users
    It seems to work and builds to scaffold. However when i try to view
    the page:
    http://localhost:3002/users

It displays this:
NameError in UsersController#index

uninitialized constant User
RAILS_ROOT: /Users/jim/Documents/work/scaffolds/config/…

Application Trace | Framework Trace | Full Trace
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/
i386/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/
dependencies.rb:123:in const_missing' /Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/ i386/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/ dependencies.rb:131:inconst_missing’
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/
i386/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/
inflector.rb:161:in constantize' /Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/ i386/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/ core_ext/string/inflections.rb:59:inconstantize’
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/
i386/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/
pagination.rb:194:in paginator_and_collection_for' /Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/ i386/lib/ruby/gems/1.8/gems/actionpack-1.12.5/lib/action_controller/ pagination.rb:129:inpaginate’
#{RAILS_ROOT}/app/controllers/users_controller.rb:12:in list' #{RAILS_ROOT}/app/controllers/users_controller.rb:3:inindex’
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/
i386/bin/mongrel_rails:18
This error occured while loading the following files:
user.rb

Help really appeciated!

[email protected] wrote:

create_table :users do |table|

script/generate scaffold users

It displays this:
NameError in UsersController#index

uninitialized constant User

This error occured while loading the following files:
user.rb

By default, Rails expects the model to be named the singular version of
the
table name.

Delete the users.rb model, the users.rb controller, and your users view
directory. Then re-run your scaffold with ‘user’ instead of ‘users’.

Best regards,
Bill

untitled wrote:

Hi im having problems using scaffolds. Im trying to do something very
simple, I dont understand the error. Hopefully someone can advise me.

  1. I’ve created my project, set my databases as SQLight and ran the
    migration: ruby script/generate migration add_a_new_table

Also, use
rake db:migrate

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs